PageSourceSearch

https://turkovichwines.com/wp-content/plugins/activ8-commerce/front/js/custom_cart_checkout.js?ver=7.1

js turkovichwines.com collected 2026-09-28 10:03:59 UTC 113,274 bytes, 2,784 lines download raw bytes

1var nc = jQuery.noConflict();
2nc(document).ready(function () {
3
4// Call on initial load
5getBasketInfo(cid='');
6updateCartInfo();
7
8//Ajax cart count on page load
9function updateCartInfo() {
10    nc.ajax({
11        url: nc('#admin_url').val(),
12        type: 'POST',
13        data: { action: 'customize_getbasket_info_onload' },
14        success: function(response) {
15            console.log(response);
16            
17            if (response.success) {
18
19                // Update cart count
20                //nc('#cart-count').text(response.data.count); 
21                
22                // Update manage Account HTML
23                nc('#sign-in-out').html(response.data.html);
24            }
25        }
26    });
27}
28//end.
29
30//checkout account signin-account Start (Login)
31nc("#cart-user-info-form").on('submit', function(event) {
32    event.preventDefault();
33    var signin_username = nc("#signin-username").val();
34    var signin_password = nc("#encryptsigninpassword").val();
35    var raw_password    = nc("#signin-password").val();
36    var allocation_id   = nc("#allocation_id").val();
37    var source          = nc("#encryptsigninpassword").data('source'); // stored original plain value
38    
39    var errors = 0;
40    nc('#cart-user-info-form :input[data-required="yes"]').map(function() {
41        if (!nc(this).val().trim()) {
42            nc(this).addClass('error');
43            errors++;
44        } else {
45            nc(this).removeClass('error');
46        }
47    });
48
49    // Empty field validation.
50    if (errors > 0) {
51        nc('#errorwarnsignin').show();
52        nc('#errorwarnsignin').html("Please fill the required fields.");
53        nc('html, body').animate({
54             scrollTop: (nc('#errorwarnsignin').offset().top - 300)
55        }, 700);
56        return false;
57        
58    } else {
59        
60        nc('#errorwarnsignin').hide('slow'); // Hide error warning.
61        
62        // If encrypted password is missing, encrypt first
63        if (raw_password !== '' && (signin_password === '' || source !== raw_password)) {
64        //if (raw_password !== '' && signin_password === '') {
65            nc.ajax({
66                type: "POST",
67                url: nc('#admin_url').val(),
68                data: "action=get_password_encrypt&result=passenc&webpassword=" + encodeURIComponent(raw_password),
69                beforeSend: function() {
70                    nc('.loader.small-loader_sign').show();
71                },
72                success: function(msg) {
73                    if (msg) {
74                        nc('#encryptsigninpassword').val(msg);
75                        signin_password = msg;
76                        cartsubmitLogin(signin_username,signin_password,allocation_id); // Call login function
77                    }
78                }
79            });
80        } else {
81            cartsubmitLogin(signin_username,signin_password,allocation_id);
82        }
83    }
84});    
85        
86//Function to handle login request and set hidden fields on checkout account signin-account 
87function cartsubmitLogin(signin_username,signin_password,allocation_id){        
88    nc.ajax({
89        type: "POST",
90        url: "" + nc('#admin_url').val() + "",
91        data: {
92            action: "custom_cart_account_signin",
93            result: "login",
94            signin_username: signin_username,
95            signin_password: signin_password, // Encode the password
96            allocation_id: allocation_id,
97        },
98        beforeSend: function() {
99            nc('.loader.small-loader_sign').show();
100        },
101        success: function(msg) {
102            if (msg) {
103                //alert(msg);
104                console.log(msg);
105                var splitted = msg.split('===');
106                
107                nc('.loader.small-loader_sign').hide();
108                nc('#final-result_sign').empty();
109                nc('#final-result_sign').html(splitted[0]);
110    
111                if (splitted[1] == 1) {
112                    document.getElementById('cart-user-info-form').submit();
113                }
114            }
115        }
116    });
117}
118//signin-account End 
119
120//Club Account login create account Start (create account)
121nc("#cart-create-user-info-form").on('submit', function(event) {
122    event.preventDefault();
123    
124    var first_name            = nc("#first-name").val();
125    var last_name             = nc("#last-name").val();
126    var user_name             = nc("#user-name").val();
127    var password              = nc("#password").val();
128    var encryptcreatepassword = nc("#encryptcreatepassword").val();
129    var allocation_id         = nc("#allocation_id").val();
130
131    //validation empty field 
132    var errors = 0;
133    nc('#create-account-form :input[data-required = "yes"]').map(function(){
134        if( !nc(this).val().trim()) {
135            nc(this).addClass('error');
136            errors++;
137        } else if (nc(this).val()) {
138            nc(this).removeClass('error');
139        }   
140    });
141
142    //Empty field validation.
143    if(errors > 0){
144        nc('#errorwarn').show();
145        nc('#errorwarn').html("Please fill the required fields.");
146        nc('html, body').animate({
147             scrollTop: (nc('#errorwarn').offset().top - 300)
148        }, 700);
149        return false;
150        
151    }else{
152        nc('#errorwarn').hide('slow'); //hide error warning.
153        nc('#cus_type').val('Register'); //Add Register to the <CustomerType>
154        
155        // Trigger the Delivery tab
156        nc('.nav-tab .nav-link').removeClass('active'); // Remove 'active' class from all tabs
157        nc('.nav-link[href="#delivery-checkout"], .nav-link[href="#shipping"]').addClass('active'); // Add 'active' class to Delivery and shipping tab
158    
159        // Display related content div
160        nc('.tab-content .tab-pane').removeClass('active show'); // Hide all other content divs
161        nc('#delivery-checkout, #shipping').addClass('active show'); // Show Delivery and shipping content div
162        nc('#create-account-form').addClass('active show');
163        nc('html, body').animate({
164             scrollTop: (nc('#errorwarn_delivery').offset().top - 300)
165        }, 700);
166    }
167});
168//create-account END
169
170//Main menu User icon drop-down on click, activate the tabs Start
171    // Check the URL for the tab parameter or hash
172    var urlParam = new URLSearchParams(window.location.search);
173    var tabParams = urlParam.get('t');
174    var loggedin = nc("#isloggedin").val();
175
176    // Hide all content divs
177    //alert(tabParams + ' ' + loggedin);
178    
179    if (tabParams == 'delivery-checkout' && loggedin == 1) { //delivery checkout params
180    
181        nc('.nav.main .nav-link').removeClass('active');
182        nc('.tab-pane.main').removeClass('active show');
183        nc('.nav-link[href="#'+tabParams+'"], .nav-link[href="#shipping"]').addClass('active'); //Tab add class active.
184        //nc('#' + tabParams +',#shipping').show().addClass('active show');
185        nc('#' + tabParams +',#shipping').addClass('active show'); 
186        nc('#pay-checkout-sec').show(); //show pay-checkout-sec section.
187        nc('#review-checkout-sec').hide(); //Hide review section.
188        
189    }else if (tabParams == 'payreview-checkout' && loggedin == 1) { //payment/review checkout params
190        
191        nc('.nav.main .nav-link').removeClass('active');
192        nc('.tab-pane.main').removeClass('active show');
193        nc('.nav-link[href="#'+tabParams+'"]').addClass('active'); //Tab add class active.
194        //nc('#' + tabParams).show().addClass('active show');
195        nc('#' + tabParams).addClass('active show');
196        nc('#pay-checkout-sec').hide(); //hide pay-checkout-sec section.
197        nc('#review-checkout-sec').show(); //Show review section.
198        
199    } else {
200        
201        // Show the first tab by default if no tab parameter or hash is found
202        nc('.nav.main .nav-link:first').show().addClass('active');
203        nc('.tab-pane.main:first').addClass('active show');
204        nc('#review-checkout-sec').hide(); //Hide review section.
205    }
206//End
207
208//Activate next tabs.
209nc('.continue.checkout').on('click', function(e){
210    e.preventDefault();
211    var tab_val = nc(this).attr("data-id");
212	
213	//activate next tab
214	var next_tab = nc('.nav a.active').parent('li').next('li').find('a');
215	if(next_tab.length > 0){
216	  nc('.nav a[href="#'+ tab_val +'"]').tab('show');
217	}
218});
219
220//Guest checkout link goes to delivery
221nc('.continue.guestcheckout').on('click', function(e){
222    e.preventDefault();
223    var tab_val = nc(this).attr("data-id");
224    nc('#cus_type').val(''); //Remove Register from the <CustomerType>
225	
226	//activate next tab
227	var next_tab = nc('.nav a.active').parent('li').next('li').find('a');
228	if(next_tab.length > 0){
229	  nc('.nav a[href="#'+ tab_val +'"]').tab('show');
230	}
231});
232
233//continue Shipping.
234nc('#delivery-checkout .continue.shipping').on('click', function(e){
235    e.preventDefault();
236    var tab_val = nc(this).data("id");
237    
238    //uncheck the billing address checkbox.
239    if (nc("#mybilling_address").prop("checked")) {
240        nc("#mybilling_address").prop("checked", false);
241    }
242
243    var errors = 0;
244    // Validation empty field where data-required = "yes".
245    nc('#delivery-checkout #shipping.active input[data-required="yes"]').each(function() {
246        if (!nc(this).val().trim()) {
247            nc(this).addClass('error');
248            nc('html, body').animate({
249                 scrollTop: (nc('.error').offset().top - 300)
250            }, 700);
251            errors++;
252        } else {
253            nc(this).removeClass('error');
254        }
255    });  
256
257    //State availablity validation 
258    var errors_state_available=0;
259    var state_available = nc('#state_available').val();
260    var shippostalcode = nc('#shipping #shippostalcode').val();
261    var shipcity = nc('#shipping #shipcity').val();
262
263    //post code availability check. 
264    if(state_available != 'Yes' && nc.trim(state_available)=="" && nc.trim(shippostalcode)!=""){  
265        //alert("postal one");                   
266        errors_state_available=1;           
267        nc('#errorwarn_postal_state').show();
268        nc("#errorwarn_postal_state").html("Please enter valid Zip Code / City.");
269        nc('html, body').animate({
270             scrollTop: (nc('#errorwarn_postal_state').offset().top - 300)
271        }, 700);
272        return false;
273    }else{       
274        //alert("postal two");           
275        errors_state_available=0;
276        //nc("#emailaddress2").removeClass("error");
277        nc("#errorwarn_postal_state").hide('slow'); //hide email error warning.
278    }
279    
280    //gift Email validation ship
281    var errors_emailaddress2=0;
282    var emailaddress2 = nc('#shipping #emailaddress2').val();
283
284    if(nc.trim(emailaddress2) != ''){ 
285        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,5})?$/;
286        
287        if( !emailReg.test(emailaddress2) ) {           
288            errors_emailaddress2=1;
289            //nc('#errorwarn').hide('slow'); 
290            nc("#shipping #emailaddress2").addClass("error");            
291            nc("#shipping #emailaddress2").focus();
292            nc('#errorwarn_email').show();
293            nc("#errorwarn_email").html("Please enter valid email.");
294            nc('html, body').animate({
295                 scrollTop: (nc('#errorwarn_email').offset().top - 300)
296            }, 700);
297            return false;
298        }else{            
299            errors_emailaddress2=0;
300            nc("#shipping #emailaddress2").removeClass("error");
301            nc("#errorwarn_email").hide('slow'); //hide email error warning.
302        }
303    }
304    
305    //Email validation ship and gift
306    var errors_emailaddress2=0;
307    var shipemail = nc('#shipemail').val();
308
309    if(nc.trim(shipemail) != ''){ 
310        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,5})?$/;
311        
312        if( !emailReg.test(shipemail) ) {           
313            errors_emailaddress2=1;
314            //nc('#errorwarn').hide('slow'); 
315            nc("#shipemail").addClass("error");            
316            nc("#shipemail").focus();
317            nc('#errorwarn_email').show();
318            nc("#errorwarn_email").html("Please enter valid email.");
319            nc('html, body').animate({
320                 scrollTop: (nc('#errorwarn_email').offset().top - 300)
321            }, 700);
322            return false;
323        }else{            
324            errors_emailaddress2=0;
325            nc("#shipemail").removeClass("error");
326            nc("#errorwarn_email").hide('slow'); //hide email error warning.
327        }
328    }
329    
330    //Empty field validation. 
331    if(errors > 0){      
332        if(errors > 0){           
333            nc('.errorwarn_delivery').show();
334            nc('.errorwarn_delivery').html("Please fill the required fields.");
335            nc('html, body').animate({
336                 scrollTop: (nc('.errorwarn_delivery').offset().top - 300)
337            }, 700);
338        } 
339        return false; 
340    }else{
341        
342        nc('#errorwarn_postal_state').hide('slow'); //hide postal code and state availableerror warning.
343        nc('.errorwarn_delivery').hide('slow'); //hide error warning.
344        nc("#errorwarn_email").hide('slow'); //hide email error warning.
345        
346        //Calling function webgetcheckoutinfo API
347        calling_getwebcheckoutinfo();
348        
349        //Enable shipview info box on Review page
350        nc('.hide_delistat').hide();
351        nc('#shipview').show();
352        nc(".icheck").show(); //Show I agree checkbox.
353        
354        //Insert value into reviews
355        //Review edits
356        //Display Customer Details in Review
357        var customername=nc('#shipfirstname').val()+' '+nc('#shiplastname').val();
358        var shipemail = nc('#shipemail').val();
359        var shipphone = nc('#shipphone').val();
360
361        //Shipping
362        var shiploc = nc('#shipcity').val()+', '+nc('#shipstate').val()+', '+nc('#shippostalcode').val();
363        nc("#display_shipaddress1").empty().html(nc('#shipaddress1').val());
364        nc("#display_shipaddress2").empty().html(nc('#shipaddress2').val());
365        nc("#display_shiploc").empty().html(shiploc);
366        
367        //Choose which name to display
368        if (customername && customername.trim() !== '') {
369           nc("#display_custname_chk").empty().text(customername);
370        }
371        
372        //Choose email
373        if (shipemail && shipemail.trim() !== '') {
374            nc("#display_shipemail_chk").empty().text(shipemail);
375        }
376        
377        //choose phone
378        if (shipphone && shipphone.trim() !== '') {
379            nc("#display_shipphone_chk").empty().text(shipphone);
380        }
381        
382        //Message
383        var giftnote = nc('#giftnotes').val();
384        var note = nc('#notes').val();
385        
386        if(!giftnote && !note){
387            nc(".hide_msgsec").hide();
388        }else{
389            nc(".hide_msgsec").show();
390        }
391        
392        if(giftnote){
393            nc("#gift_msg_title").show();
394            nc("#display_gift_msg").empty().html(giftnote);
395        }else{
396            nc("#gift_msg_title").hide();
397            nc("#display_gift_msg").empty();
398        }
399        
400        if(note){
401            nc("#deli_msg_title").show();
402            nc("#display_deli_msg").empty().html(note);
403        }else{
404            nc("#deli_msg_title").hide();
405            nc("#display_deli_msg").empty();
406        }
407        //review ends.
408        
409        //activate next tab
410        var next_tab = nc('.nav a.active').parent('li').next('li').find('a');
411        if(next_tab.length>0){
412          nc('.nav a[href="#'+ tab_val +'"]').tab('show');
413        }
414        nc('html, body').animate({
415             scrollTop: (nc('#rev_errorwarn').offset().top - 300) 
416        }, 700); //scroll top on creditcard tab
417    }
418});
419
420//Continue Pickup
421nc('#delivery-checkout .continue.pickup').on('click', function(e){
422    e.preventDefault();
423    var tab_val = nc(this).data("id");
424    
425    //uncheck the billing address checkbox.
426    if (nc("#mybilling_address").prop("checked")) {
427        nc("#mybilling_address").prop("checked", false);
428    }
429
430    var errors = 0;
431    // Validation empty field where data-required = "yes".
432    nc('#delivery-checkout #pickup.active input[data-required="yes"]').each(function() {
433        if (!nc(this).val().trim()) {
434            nc(this).addClass('error');
435            errors++;
436        } else {
437            nc(this).removeClass('error');
438        }
439    });
440    
441    //Pickup Email validation ship
442    var errors_emailaddress2=0;
443    var pickupemail = nc('#pickupemail').val();
444
445    if(nc.trim(pickupemail) != ''){ 
446        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,5})?$/;
447        
448        if( !emailReg.test(pickupemail) ) {           
449            errors_emailaddress2=1;
450            //nc('#errorwarn').hide('slow'); 
451            nc("#pickupemail").addClass("error");            
452            nc("#pickupemail").focus();
453            nc('#errorwarn_email').show();
454            nc("#errorwarn_email").html("Please enter valid email.");
455            nc('html, body').animate({
456                 scrollTop: (nc('#errorwarn_email').offset().top - 300) 
457            }, 700); //scroll top on email error warn
458            return false;
459        }else{            
460            errors_emailaddress2=0;
461            nc("#pickupemail").removeClass("error");
462            nc("#errorwarn_email").hide('slow'); //hide email error warning.
463        }
464    }
465    
466    //select dropdown validation
467    if (nc("#pickuplocation").val() === '') {
468        nc("#pickuplocation").addClass('error');
469        errors = 1;
470    }
471
472    //Empty field validation.
473    if(errors > 0){        
474        if(errors > 0){
475            nc('.errorwarn_delivery').show();
476            nc('.errorwarn_delivery').html("Please fill the required fields.");
477            nc('html, body').animate({
478                 scrollTop: (nc('.errorwarn_delivery').offset().top - 300)
479            }, 700);
480        }
481        return false;        
482    }else{        
483        
484        nc('.errorwarn_delivery').hide('slow'); //hide error warning.
485        
486        //Calling function webgetcheckoutinfo API
487        calling_getwebcheckoutinfo();
488        
489        //Enable Pickupview info on Review page
490        nc('.hide_delistat').hide();
491        nc('#pickupview').show();
492        nc(".icheck").hide(); //Hide I agree checkbox.
493        
494        
495        //Review edits
496        //Display Customer Details in Review
497        //Pickup
498        var avsloc = nc("#avscity").val()+', '+nc("#avsstate").val()+', '+nc("#avspostalcode").val();
499        var pickname=nc("#pickupfirstname").val()+' '+nc("#pickuplastname").val();
500        var pickemail = nc("#pickupemail").val(); 
501        nc("#display_pickuplocation").empty().html(nc("#checkout_pickuplocation").val());
502        nc("#display_avsaddress").empty().html(nc("#avsaddress").val());
503        nc("#display_avsloc").empty().html(avsloc);
504        
505        // Choose which name to display
506        if (pickname && pickname.trim() !== '') {
507            nc("#display_custname_chk").empty().text(pickname);
508        }
509        
510        //choose email
511        if (pickemail && pickemail.trim() !== '') {
512            nc("#display_shipemail_chk").empty().text(pickemail);
513        }
514        //Review end
515
516        //activate next tab
517        var next_tab = nc('.nav a.active').parent('li').next('li').find('a');
518        if(next_tab.length>0){
519           nc('.nav a[href="#'+ tab_val +'"]').tab('show');
520        }
521        nc('html, body').animate({
522             scrollTop: (nc('#rev_errorwarn').offset().top - 300)
523        }, 700); //scroll top on creditcard tab
524    }    
525});
526
527//continue Delivery.
528nc('#delivery-checkout .continue.delivery').on('click', function(e){
529    e.preventDefault();
530    var tab_val = jQuery(this).data("id");
531    
532    //uncheck the billing address checkbox.
533    if (nc("#mybilling_address").prop("checked")) {
534        nc("#mybilling_address").prop("checked", false);
535    }
536
537    var errors = 0;
538    // Validation empty field where data-required = "yes".
539    jQuery('#delivery-checkout #delivery.active input[data-required="yes"]').each(function() {
540        if (!jQuery(this).val().trim()) {
541            jQuery(this).addClass('error');
542            jQuery('html, body').animate({
543                 scrollTop: (jQuery('.error').offset().top - 300)
544            }, 700);
545            errors++;
546        } else {
547            jQuery(this).removeClass('error');
548        }
549    });  
550
551    //State availablity validation 
552    var errors_state_available=0;
553    var state_available = jQuery('#state_available').val();
554    var shippostalcode = jQuery('#delivery #delipostalcode').val();
555    var shipcity = jQuery('#delivery #delicity').val();
556
557    //post code availability check. 
558    if(state_available != 'Yes' && jQuery.trim(state_available)=="" && jQuery.trim(shippostalcode)!=""){  
559        //alert("postal one");                   
560        errors_state_available=1;           
561        jQuery('#errorwarn_postal_state').show();
562        jQuery("#errorwarn_postal_state").html("Please enter valid Zip Code / City.");
563        jQuery('html, body').animate({
564             scrollTop: (jQuery('#errorwarn_postal_state').offset().top - 300)
565        }, 700);
566        return false;
567    }else{       
568        //alert("postal two");           
569        errors_state_available=0;
570        jQuery("#errorwarn_postal_state").hide('slow'); //hide email error warning.
571    }
572    
573    //Email validation ship
574    var errors_emailaddress=0;
575    var shipemail = jQuery('#delivery #deliemail').val();
576
577    if(jQuery.trim(shipemail) != ''){ 
578        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,5})?$/;
579        
580        if( !emailReg.test(shipemail) ) {           
581            errors_emailaddress=1;
582            //jQuery('#errorwarn').hide('slow'); 
583            jQuery("#delivery #deliemail").addClass("error");            
584            jQuery("#delivery #deliemail").focus();
585            jQuery('#errorwarn_email').show();
586            jQuery("#errorwarn_email").html("Please enter valid Email.");
587            nc('html, body').animate({
588                 scrollTop: (nc('#errorwarn_email').offset().top - 300) 
589            }, 700); //scroll top on email error warn
590            return false;
591        }else{            
592            errors_emailaddress=0;
593            jQuery("#delivery #deliemail").removeClass("error");
594            jQuery("#errorwarn_email").hide('slow'); //hide email error warning.
595        }
596    }
597    
598    //Empty field validation. 
599    if(errors > 0){      
600        if(errors > 0){           
601            jQuery('.errorwarn_delivery').show();
602            jQuery('.errorwarn_delivery').html("Please fill the required fields.");
603        } 
604        return false; 
605    }else{      
606        jQuery('#errorwarn_postal_state').hide('slow'); //hide postal code and state availableerror warning.
607        jQuery('.errorwarn_delivery').hide('slow'); //hide error warning.
608        jQuery("#errorwarn_email").hide('slow'); //hide email error warning.
609        
610        //Calling function webgetcheckoutinfo API
611        calling_getwebcheckoutinfo();
612        
613        //Enable deliview info on Review page
614        jQuery('.hide_delistat').hide();
615        jQuery('#deliview').show();
616        jQuery(".icheck").show(); //Show I agree checkbox.
617        
618        //Review edit
619        //Display Customer Details in Review
620        //Delivery
621        var deliname = nc("#delifirstname").val()+' '+nc("#delilastname").val();
622        var dloc = nc("#delicity").val()+', '+nc("#delistate").val()+', '+nc("#delipostalcode").val();
623        var deliemail = nc("#deliemail").val(); 
624        var deliphone = nc("#deliphone").val();
625        nc("#display_deliaddress1").empty().html(nc("#deliaddress1").val());
626        nc("#display_deliaddress2").empty().html(nc("#deliaddress2").val());
627        nc("#display_deliloc").empty().html(dloc);
628        
629        // Choose which name to display
630        if (deliname && deliname.trim() !== '') {
631            nc("#display_custname_chk").empty().text(deliname);
632        }
633        
634        //Choose email
635        if (deliemail && deliemail.trim() !== '') {
636            nc("#display_shipemail_chk").empty().text(deliemail);
637        }
638        
639        //choose phone
640        if (deliphone && deliphone.trim() !== '') {
641            nc("#display_shipphone_chk").empty().text(deliphone);
642        }
643        //Review end
644        
645        //activate next tab
646        var next_tab = jQuery('.nav a.active').parent('li').next('li').find('a');
647        if(next_tab.length>0){
648          nc('.nav a[href="#'+ tab_val +'"]').tab('show');
649        }
650        nc('html, body').animate({
651             scrollTop: (nc('#rev_errorwarn').offset().top - 300)
652        }, 700); //scroll top to creditcard tab.
653    }
654});
655
656//continue PAYMENT/REVIEW.
657/*nc(document).on('click', '#payreview-checkout .continue.review-cont', function(e){
658    e.preventDefault();
659    
660    //Review edits
661    //Display Customer Details in Review
662    var customername=nc('#shipfirstname').val()+' '+nc('#shiplastname').val();
663    var shipemail = nc('#shipemail').val();
664    var shipphone = nc('#shipphone').val();
665
666    //Shipping
667    var shiploc = nc('#shipcity').val()+', '+nc('#shipstate').val()+', '+nc('#shippostalcode').val();
668    nc("#display_shipaddress1").empty().html(nc('#shipaddress1').val());
669    nc("#display_shipaddress2").empty().html(nc('#shipaddress2').val());
670    nc("#display_shiploc").empty().html(shiploc);
671    
672    //Pickup
673    var avsloc = nc("#avscity").val()+', '+nc("#avsstate").val()+', '+nc("#avspostalcode").val();
674    var pickname=nc("#pickupfirstname").val()+' '+nc("#pickuplastname").val();
675    var pickemail = nc("#pickupemail").val(); 
676    nc("#display_pickuplocation").empty().html(nc("#checkout_pickuplocation").val());
677    nc("#display_avsaddress").empty().html(nc("#avsaddress").val());
678    nc("#display_avsloc").empty().html(avsloc);
679    
680    //Delivery
681    var deliname = nc("#delifirstname").val()+' '+nc("#delilastname").val();
682    var dloc = nc("#delicity").val()+', '+nc("#delistate").val()+', '+nc("#delipostalcode").val();
683    var deliemail = nc("#deliemail").val();
684    var deliphone = nc("#deliphone").val();
685    nc("#display_deliaddress1").empty().html(nc("#deliaddress1").val());
686    nc("#display_deliaddress2").empty().html(nc("#deliaddress2").val());
687    nc("#display_deliloc").empty().html(dloc);
688    
689    
690    // Choose which name to display
691    if (pickname && pickname.trim() !== '') {
692        nc("#display_custname_chk").empty().text(pickname);
693    } else if (deliname && deliname.trim() !== '') {
694        nc("#display_custname_chk").empty().text(deliname);
695    } else {
696        nc("#display_custname_chk").empty().text(customername);
697    }
698    
699    //Choose email
700    if (shipemail && shipemail.trim() !== '') {
701        nc("#display_shipemail_chk").empty().text(shipemail);
702    } else if (pickemail && pickemail.trim() !== '') {
703        nc("#display_shipemail_chk").empty().text(pickemail);
704    } else {
705        nc("#display_shipemail_chk").empty().text(deliemail);
706    }
707    
708    //choose phone
709    if (shipphone && shipphone.trim() !== '') {
710        nc("#display_shipphone_chk").empty().text(shipphone);
711    } else {
712        nc("#display_shipphone_chk").empty().text(deliphone);
713    }
714    
715    //Message
716    var giftnote = nc('#giftnotes').val();
717    var giftmail = nc('#shipping #emailaddress2').val();
718    var note = nc('#notes').val();
719    
720    if(!giftnote && !note){
721        nc(".hide_msgsec").hide();
722    }else{
723        nc(".hide_msgsec").show();
724    }
725    
726    if(giftnote){
727        nc("#gift_msg_title").show();
728        nc("#display_gift_msg").empty().html(giftnote);
729    }else{
730        nc("#gift_msg_title").hide();
731        nc("#display_gift_msg").empty();
732    }
733    
734    if(note){
735        nc("#deli_msg_title").show();
736        nc("#display_deli_msg").empty().html(note);
737    }else{
738        nc("#deli_msg_title").hide();
739        nc("#display_deli_msg").empty();
740    }
741    //review ends.
742    
743    //Display Payment Details in Review
744    var customerid = nc('#hid_customerid').val();
745    var creditcardnum = nc('#creditcardnum').val();
746    var creditcardtype = nc('#hid_creditcardtype').val();
747    if(creditcardtype && creditcardtype.trim() !== ''){
748        creditcardtype = creditcardtype;
749    }else{
750        creditcardtype = '';
751    }
752    var creditcardnum_last4 = '**** **** '+creditcardnum.substr(creditcardnum.length - 4);
753    nc("#display_creditcardnum").html(creditcardtype +' '+creditcardnum_last4);
754    var expirationmonth = nc('#expirationmonth').val();
755    var expirationyear = nc('#expirationyear').val();
756    nc("#display_creditcardexpiry").html('Expiration: '+expirationmonth+'/'+expirationyear);
757    
758    let update_card = nc("#update_card").prop("checked") ? nc('#update_card').val() : ''; //Yes
759    
760    var errors = 0;
761    // Validation empty field where data-required = "yes".
762    nc('#payreview-checkout.active .credit-cards input[data-required="yes"]').each(function() {
763        if (!nc(this).val().trim()) {
764            nc(this).addClass('error');
765            nc('html, body').animate({
766                 scrollTop: (nc('.error').offset().top - 400)
767            }, 700);
768            errors++;
769        } else {
770            nc(this).removeClass('error');
771        }
772    });
773    
774    // If there are empty fields, stop execution
775    if (errors > 0) {
776        nc('#rev_errorwarn').show();
777        nc('#rev_errorwarn').empty().html("Please fill the required fields.");
778        return false;
779    }else{
780        nc('#rev_errorwarn').hide();
781    }
782    
783    //Check if the credictcard field is not with XXXXXXXXXXXX.
784    if (creditcardnum && !String(creditcardnum).startsWith('XXXXXXXXXXXX')) {
785        
786        //Credit Card Validation
787        var errors_credit=0;
788        //var cardNumber = nc("#creditcardnum").val();
789        var cvv = nc("#creditcardcvv2").val();
790        var encCardNum = nc("#encrypt_creditcardnum").val();
791    
792        jQuery.ajax({
793            type: "POST",
794            url:""+nc('#admin_url').val()+"", 
795            data: {
796                action: "custom_validate_creditcard_payment",
797                result: "validate_cardpayment",
798                card_num: encCardNum,
799                expirationmonth: expirationmonth,
800                expirationyear: expirationyear,
801                cvv:cvv,
802                customerid: customerid,
803                update_card: update_card,
804            },
805            beforeSend: function(){
806                nc('.loader.small-loader_review').show();
807            },              
808            success: function(msg){
809                if(msg){
810                    var splitted = msg.split('===');
811                    console.log(msg);
812                    //alert(msg);
813                    
814                    if(splitted[0] > 0){
815                        //after validate code will come here.
816                        var creditcardnum = splitted[2];
817                        var vaultid = splitted[3];
818                        var expirationmonth = splitted[4];
819                        var expirationyear = splitted[5];
820                        var creditcardtype = splitted[6];
821                        var cardnum_last4 = '**** **** '+creditcardnum.substr(creditcardnum.length - 4);
822                        
823                        nc("#errorwarn_creditcard").hide(); //hide credit card error warning.
824                        nc("#hid_creditcardnum,#creditcardnum").val(creditcardnum);
825                        nc("#hid_vaultid").val(vaultid);
826                        nc("#hid_expirationmonth").val(expirationmonth);
827                        nc("#hid_expirationyear").val(expirationyear);
828                        nc('#hid_creditcardtype').val(creditcardtype);
829                        nc("#display_creditcardnum").html(creditcardtype +' '+cardnum_last4);
830                        
831                        //Calling function webgetcheckoutinfo API
832                        calling_getwebcheckoutinfo(); 
833            
834                        // Proceed to checkout
835                        nc('.loader.small-loader_review').hide(); //hide loader.
836                        nc('#pay-checkout-sec').hide();
837                        nc('#review-checkout-sec').show();
838        
839                    }else if(splitted[0] === ''){ //if basket due total is 0.00 and gift card balance not 0.00, remove credit card validation 
840                        
841                        //Calling function webgetcheckoutinfo API
842                        calling_getwebcheckoutinfo(); 
843            
844                        // Proceed to checkout
845                        nc('.loader.small-loader_review').hide(); //hide loader.
846                        nc('#pay-checkout-sec').hide();
847                        nc('#review-checkout-sec').show();
848                        
849                    }else{
850                        errors_credit=1;
851                        nc('#errorwarn_creditcard').show();
852                        nc("#errorwarn_creditcard").empty().html(splitted[1]);
853                        nc('.loader.small-loader_review').hide(); //hide loader.
854                        nc('html, body').animate({
855                             scrollTop: (nc('#errorwarn_creditcard').offset().top - 300)
856                        }, 700); //scroll top to creditcard tab.
857                        return false;
858                    }
859                    nc('html, body').animate({
860                         scrollTop: (nc('#errorwarn_creditcard').offset().top - 300)
861                    }, 700); //scroll top to creditcard tab.
862                } 
863            }
864        });
865        
866    }else{
867        // Proceed to checkout
868        nc('#pay-checkout-sec').hide();
869        nc('#review-checkout-sec').show();
870    }
871
872});*/
873nc(document).on('click', '#payreview-checkout .continue.review-cont', function(e){
874    e.preventDefault();
875    
876	// Show loader
877    nc('.loader.small-loader_review').show();
878
879    // STEP 1: CAPTCHA Validation
880    var captchaInput = nc('#captcha_input').val();
881
882    jQuery.ajax({
883        type: "POST",
884        url: nc('#admin_url').val(),
885        data: {
886            action: 'validate_custom_captcha',
887            captcha_input: captchaInput
888        },
889        success: function(response) {
890            //console.error(response);
891            
892            if (!response.success) {
893                // Show CAPTCHA error
894                nc('#captcha_error').show();
895
896                // Refresh image
897                nc('#captcha-img').attr('src', myplugin_vars.plugin_url + 'includes/generate-captcha.php?rand=' + Date.now());
898
899                /*nc('html, body').animate({
900                    scrollTop: (nc('#captcha_error').offset().top - 300)
901                }, 700);*/
902
903                nc('.loader.small-loader_review').hide();
904                return false;
905                
906            } else {
907                
908                nc('#captcha_error').hide();
909    
910				//Review edits
911				//Display Customer Details in Review
912				var customername=nc('#shipfirstname').val()+' '+nc('#shiplastname').val();
913				var shipemail = nc('#shipemail').val();
914				var shipphone = nc('#shipphone').val();
915
916				//Shipping
917				var shiploc = nc('#shipcity').val()+', '+nc('#shipstate').val()+', '+nc('#shippostalcode').val();
918				nc("#display_shipaddress1").empty().html(nc('#shipaddress1').val());
919				nc("#display_shipaddress2").empty().html(nc('#shipaddress2').val());
920				nc("#display_shiploc").empty().html(shiploc);
921				
922				//Pickup
923				var avsloc = nc("#avscity").val()+', '+nc("#avsstate").val()+', '+nc("#avspostalcode").val();
924				var pickname=nc("#pickupfirstname").val()+' '+nc("#pickuplastname").val();
925				var pickemail = nc("#pickupemail").val(); 
926				nc("#display_pickuplocation").empty().html(nc("#checkout_pickuplocation").val());
927				nc("#display_avsaddress").empty().html(nc("#avsaddress").val());
928				nc("#display_avsloc").empty().html(avsloc);
929				
930				//Delivery
931				var deliname = nc("#delifirstname").val()+' '+nc("#delilastname").val();
932				var dloc = nc("#delicity").val()+', '+nc("#delistate").val()+', '+nc("#delipostalcode").val();
933				var deliemail = nc("#deliemail").val();
934				var deliphone = nc("#deliphone").val();
935				nc("#display_deliaddress1").empty().html(nc("#deliaddress1").val());
936				nc("#display_deliaddress2").empty().html(nc("#deliaddress2").val());
937				nc("#display_deliloc").empty().html(dloc);
938				
939				
940				// Choose which name to display
941				if (pickname && pickname.trim() !== '') {
942					nc("#display_custname_chk").empty().text(pickname);
943				} else if (deliname && deliname.trim() !== '') {
944					nc("#display_custname_chk").empty().text(deliname);
945				} else {
946					nc("#display_custname_chk").empty().text(customername);
947				}
948				
949				//Choose email
950				if (shipemail && shipemail.trim() !== '') {
951					nc("#display_shipemail_chk").empty().text(shipemail);
952				} else if (pickemail && pickemail.trim() !== '') {
953					nc("#display_shipemail_chk").empty().text(pickemail);
954				} else {
955					nc("#display_shipemail_chk").empty().text(deliemail);
956				}
957				
958				//choose phone
959				if (shipphone && shipphone.trim() !== '') {
960					nc("#display_shipphone_chk").empty().text(shipphone);
961				} else {
962					nc("#display_shipphone_chk").empty().text(deliphone);
963				}
964				
965				//Message
966				var giftnote = nc('#giftnotes').val();
967				var giftmail = nc('#shipping #emailaddress2').val();
968				var note = nc('#notes').val();
969				
970				if(!giftnote && !note){
971					nc(".hide_msgsec").hide();
972				}else{
973					nc(".hide_msgsec").show();
974				}
975				
976				if(giftnote){
977					nc("#gift_msg_title").show();
978					nc("#display_gift_msg").empty().html(giftnote);
979				}else{
980					nc("#gift_msg_title").hide();
981					nc("#display_gift_msg").empty();
982				}
983				
984				if(note){
985					nc("#deli_msg_title").show();
986					nc("#display_deli_msg").empty().html(note);
987				}else{
988					nc("#deli_msg_title").hide();
989					nc("#display_deli_msg").empty();
990				}
991				//review ends.
992				
993				//Display Payment Details in Review
994				var customerid = nc('#hid_customerid').val();
995				var creditcardnum = nc('#creditcardnum').val();
996				var creditcardtype = nc('#hid_creditcardtype').val();
997				if(creditcardtype && creditcardtype.trim() !== ''){
998					creditcardtype = creditcardtype;
999				}else{
1000					creditcardtype = '';
1001				}
1002				var creditcardnum_last4 = '**** **** '+creditcardnum.substr(creditcardnum.length - 4);
1003				nc("#display_creditcardnum").html(creditcardtype +' '+creditcardnum_last4);
1004				var expirationmonth = nc('#expirationmonth').val();
1005				var expirationyear = nc('#expirationyear').val();
1006				nc("#display_creditcardexpiry").html('Expiration: '+expirationmonth+'/'+expirationyear);
1007				
1008				let update_card = nc("#update_card").prop("checked") ? nc('#update_card').val() : ''; //Yes
1009				
1010				var errors = 0;
1011				// Validation empty field where data-required = "yes".
1012				nc('#payreview-checkout.active .credit-cards input[data-required="yes"]').each(function() {
1013					if (!nc(this).val().trim()) {
1014						nc(this).addClass('error');
1015						nc('html, body').animate({
1016							 scrollTop: (nc('.error').offset().top - 400)
1017						}, 700);
1018						errors++;
1019					} else {
1020						nc(this).removeClass('error');
1021					}
1022				});
1023				
1024				// If there are empty fields, stop execution
1025				if (errors > 0) {
1026					nc('#rev_errorwarn').show();
1027					nc('#rev_errorwarn').empty().html("Please fill the required fields.");
1028					return false;
1029				}else{
1030					nc('#rev_errorwarn').hide();
1031				}
1032				
1033				//Check if the credictcard field is not with XXXXXXXXXXXX.
1034				if (creditcardnum && !String(creditcardnum).startsWith('XXXXXXXXXXXX')) {
1035					
1036					//Credit Card Validation
1037					var errors_credit=0;
1038					//var cardNumber = nc("#creditcardnum").val();
1039					var cvv = nc("#creditcardcvv2").val();
1040					var encCardNum = nc("#encrypt_creditcardnum").val();
1041				
1042					jQuery.ajax({
1043						type: "POST",
1044						url:""+nc('#admin_url').val()+"", 
1045						data: {
1046							action: "custom_validate_creditcard_payment",
1047							result: "validate_cardpayment",
1048							card_num: encCardNum,
1049							expirationmonth: expirationmonth,
1050							expirationyear: expirationyear,
1051							cvv:cvv,
1052							customerid: customerid,
1053							update_card: update_card,
1054						},
1055						beforeSend: function(){
1056							nc('.loader.small-loader_review').show();
1057						},              
1058						success: function(msg){
1059							if(msg){
1060								var splitted = msg.split('===');
1061								console.log(msg);
1062								//alert(msg);
1063								
1064								if(splitted[0] > 0){
1065									//after validate code will come here.
1066									var creditcardnum = splitted[2];
1067									var vaultid = splitted[3];
1068									var expirationmonth = splitted[4];
1069									var expirationyear = splitted[5];
1070									var creditcardtype = splitted[6];
1071									var cardnum_last4 = '**** **** '+creditcardnum.substr(creditcardnum.length - 4);
1072									
1073									nc("#errorwarn_creditcard").hide(); //hide credit card error warning.
1074									nc("#hid_creditcardnum,#creditcardnum").val(creditcardnum);
1075									nc("#hid_vaultid").val(vaultid);
1076									nc("#hid_expirationmonth").val(expirationmonth);
1077									nc("#hid_expirationyear").val(expirationyear);
1078									nc('#hid_creditcardtype').val(creditcardtype);
1079									nc("#display_creditcardnum").html(creditcardtype +' '+cardnum_last4);
1080									
1081									//Calling function webgetcheckoutinfo API
1082									calling_getwebcheckoutinfo(); 
1083						
1084									// Proceed to checkout
1085									nc('.loader.small-loader_review').hide(); //hide loader.
1086									nc('#pay-checkout-sec').hide();
1087									nc('#review-checkout-sec').show();
1088					
1089								}else if(splitted[0] === ''){ //if basket due total is 0.00 and gift card balance not 0.00, remove credit card validation 
1090									
1091									//Calling function webgetcheckoutinfo API
1092									calling_getwebcheckoutinfo(); 
1093						
1094									// Proceed to checkout
1095									nc('.loader.small-loader_review').hide(); //hide loader.
1096									nc('#pay-checkout-sec').hide();
1097									nc('#review-checkout-sec').show();
1098									
1099								}else{
1100									errors_credit=1;
1101									nc('#errorwarn_creditcard').show();
1102									nc("#errorwarn_creditcard").empty().html(splitted[1]);
1103									nc('.loader.small-loader_review').hide(); //hide loader.
1104									nc('html, body').animate({
1105										 scrollTop: (nc('#errorwarn_creditcard').offset().top - 300)
1106									}, 700); //scroll top to creditcard tab.
1107									return false;
1108								}
1109								nc('html, body').animate({
1110									 scrollTop: (nc('#errorwarn_creditcard').offset().top - 300)
1111								}, 700); //scroll top to creditcard tab.
1112							} 
1113						}
1114					});
1115					
1116				}else{
1117					// Proceed to checkout
1118					nc('#pay-checkout-sec').hide();
1119					nc('#review-checkout-sec').show();
1120				}
1121	        } // End of else (captcha passed)
1122        } // End success
1123    }); // End AJAX
1124});
1125
1126//Sbumit final button Complete Order.
1127nc(document).on('submit', '#review-checkout-sec', function(event){
1128    event.preventDefault(); // Prevent page reload
1129    
1130    var iagreechk = nc("#iagree_chk").val();
1131    var islogin   = nc('#hid_isloggedin').val(); //check is login.
1132    var deliveryType = nc("#delivery-checkout .nav .nav-link.active").attr("data-delivery");
1133    
1134    var username = nc('#user-name').val();
1135    var userpass = nc('#encryptcreatepassword').val();
1136    var cus_type = nc('#cus_type').val();
1137    
1138    //If pickup is enabled, checkbox not showing
1139    if(deliveryType !== 'Pickup'){
1140        // Check if the "I agree" checkbox is checked
1141        if (iagreechk === 'Yes' && !nc("#iagree").prop("checked")) {
1142            alert("You must agree to the Shipping Terms and Conditions before proceeding.");
1143            return false; // Stop form submission
1144        }
1145    }
1146    
1147    //Check customer type
1148    if(cus_type && cus_type === 'Register'){
1149        var customer_type = 'Register';
1150    }else{
1151        if (islogin && islogin === "1") {
1152            var customer_type = 'Login';
1153        }else{
1154            var customer_type = 'Guest';
1155        }
1156    }
1157    
1158    var delivery_type   = nc('#delivery-checkout .nav-item .nav-link.active').attr('data-delivery');
1159    var discountcode    = nc('#discount-code').val();
1160    var token           = nc("#hid_vaultid").val(); //token taken from hidden after adding creditcard.
1161    var creditcardtype  = nc("#hid_creditcardtype").val(); //card type taken from hidden after adding creditcard.
1162    
1163    //Shipping
1164    var shipfirstname   = nc("#shipfirstname").val();
1165    var shiplastname    = nc("#shiplastname").val();
1166    var shipemail       = nc("#shipemail").val();
1167    var shipbirthdate   = nc("#shipbirthdate").val();
1168    var shipcompanyname = nc("#shipcompanyname").val();
1169    var shipaddress1    = nc("#shipaddress1").val();
1170    var shipaddress2    = nc("#shipaddress2").val();
1171    var shippostalcode  = nc("#shippostalcode").val();
1172    var shipcity        = nc("#shipcity").val();
1173    var shipstate       = nc("#shipstate").val();
1174    var shipphone       = nc("#shipphone").val();
1175    var shippingoption  = nc("#shipping-option").val(); //service
1176    var shippingmethod  = nc("#shipping-method").val(); //method
1177    var isgift          = nc("#isgift").prop("checked") ? nc("#isgift").val() : "";
1178    var giftnotes       = nc("#giftnotes").val();
1179    var emailaddress2   = nc("#emailaddress2").val();
1180    var notes           = nc("#notes").val();
1181
1182    //pickup 
1183    var pickupfirstname = nc("#pickupfirstname").val();
1184    var pickuplastname  = nc("#pickuplastname").val();
1185    var pickupemail     = nc("#pickupemail").val();
1186    var birthdate       = nc("#birthdate").val();
1187    var checkout_pickuplocation = nc("#checkout_pickuplocation").val();
1188    
1189    //delivery
1190    var delifirstname   = nc("#delifirstname").val();
1191    var delilastname    = nc("#delilastname").val();
1192    var deliemail       = nc("#deliemail").val();
1193    var delicompanyname = nc("#delicompanyname").val();
1194    var deliaddress1    = nc("#deliaddress1").val();
1195    var deliaddress2    = nc("#deliaddress2").val();
1196    var delipostalcode  = nc("#delipostalcode").val();
1197    var delicity        = nc("#delicity").val();
1198    var delistate       = nc("#delistate").val();
1199    var deliphone       = nc("#deliphone").val();
1200    
1201    //PAYMENT/REVIEW
1202    var gift_card_num    = nc("#gift-card-num").val();
1203    var security_code    = nc("#security-code").val();
1204    var giftcard_id      = nc("#gifcrd_id").val();
1205    var giftcard_bal     = nc("#gifcrd_bal").val();
1206    var useloyaltypoints = nc("#redeem-loyal-point").prop("checked") ? nc("#redeem-loyal-point").val() : 0;
1207    
1208    var creditcardnum   = nc("#hid_creditcardnum").val();
1209    var expitationmonth = nc("#hid_expirationmonth").val();
1210    var expitationyear  = nc("#hid_expirationyear").val();
1211    //var creditcardcvv2  = nc("#creditcardcvv2").val();
1212    var avsaddress      = nc("#avsaddress").val();
1213    var avspostalcode   = nc("#avspostalcode").val();
1214    var avscity         = nc("#avscity").val();
1215    var avsstate        = nc("#avsstate").val();
1216    var allocation_id   = nc("#allocation_id").val();
1217    
1218    jQuery.ajax({
1219        type: "POST",
1220        url:""+jQuery('#admin_url').val()+"", 
1221        data: {
1222            action: "custom_complete_order",
1223            result: "complete_order",
1224            delivery_type   : delivery_type,
1225            customer_type   : customer_type,
1226            discountcode    : discountcode,
1227            token           : token,
1228            creditcardtype  : creditcardtype,
1229            shipfirstname   : shipfirstname,
1230            shiplastname    : shiplastname,
1231            shipemail       : shipemail,
1232            shipbirthdate   : shipbirthdate,
1233            shipcompanyname : shipcompanyname,
1234            shipaddress1    : shipaddress1,
1235            shipaddress2    : shipaddress2,
1236            shippostalcode  : shippostalcode,
1237            shipcity        : shipcity,
1238            shipstate       : shipstate,
1239            shipphone       : shipphone,
1240            shippingoption  : shippingoption,
1241            shippingmethod  : shippingmethod,
1242            isgift          : isgift,
1243            giftnotes       : giftnotes, //no element
1244            emailaddress2   : emailaddress2,
1245            notes           : notes,
1246            pickupfirstname : pickupfirstname,
1247            pickuplastname  : pickuplastname,
1248            pickupemail     : pickupemail,
1249            birthdate       : birthdate,
1250            checkout_pickuplocation : checkout_pickuplocation,
1251            delifirstname   : delifirstname,
1252            delilastname    : delilastname,
1253            deliemail       : deliemail,
1254            delicompanyname : delicompanyname,
1255            deliaddress1    : deliaddress1,
1256            deliaddress2    : deliaddress2,
1257            delipostalcode  : delipostalcode,
1258            delicity        : delicity,
1259            delistate       : delistate,
1260            deliphone       : deliphone,
1261            gift_card_num   : gift_card_num,
1262            security_code   : security_code,
1263            giftcard_id     : giftcard_id,
1264            giftcard_bal    : giftcard_bal,
1265            useloyaltypoints: useloyaltypoints,
1266            creditcardnum   : creditcardnum,
1267            expitationmonth : expitationmonth,
1268            expitationyear  : expitationyear,
1269            //creditcardcvv2 : creditcardcvv2,
1270            avsaddress      : avsaddress,
1271            avspostalcode   : avspostalcode,
1272            avscity         : avscity,
1273            avsstate        : avsstate,
1274            allocation_id   : allocation_id,
1275            username        : username,
1276            userpass        : userpass,
1277        },
1278        beforeSend: function(){
1279            nc('.loader.small-loader_completeorder').show();
1280        },              
1281        success: function(msg){
1282            if(msg){
1283                var splitted = msg.split('===');
1284                console.log(msg);
1285                
1286                nc('.loader.small-loader_completeorder').hide();
1287                
1288                if(splitted[0] > 0){
1289                    //nc('#review-checkout-sec').hide();
1290                    //nc('#thank-you-message').show();
1291                    //nc('#thank-you-message').empty().html(splitted[1]);
1292                    //nc('.nav.main').hide();
1293                    // redirect to new thank you page..... after success...
1294                    window.location.href = window.location.origin + "/acs-thank-you";
1295                }else{
1296                    nc('#thank-you-message').hide();
1297                    nc('#completeorder-final-result').empty().html(splitted[1]);
1298                }
1299            } 
1300        }
1301    });
1302});
1303
1304//calculate delivery fee button click
1305nc(document).on('click', '#cal-deli-fee', function(){
1306
1307    var errors = 0;
1308    // Validation empty field where data-required = "yes".
1309    jQuery('#delivery-checkout .tab-pane.active input[data-required="yes"]').each(function() {
1310        if (!jQuery(this).val().trim()) {
1311            jQuery(this).addClass('error');
1312            jQuery('html, body').animate({
1313                 scrollTop: (jQuery('.error').offset().top - 300)
1314            }, 700);
1315            errors++;
1316        } else {
1317            jQuery(this).removeClass('error');
1318        }
1319    });
1320	
1321	//Empty field validation. 
1322    if(errors > 0){      
1323        if(errors > 0){           
1324            jQuery('.errorwarn_delivery').show();
1325            jQuery('.errorwarn_delivery').html("Please fill the required fields.");
1326        } 
1327        return false; 
1328    }else{
1329	    nc("#cal-deli-fee").empty().html('<i style="font-size: 16px;" class="fa fa-circle-thin me-2"></i>Loading...');
1330        
1331        //Calling function webgetcheckoutinfo API
1332        calling_getwebcheckoutinfo();  
1333	}
1334});
1335//End
1336
1337//Call getwebcheckoutinfo on each delivery tabs clicks(ship,pickup,delivery)
1338/*nc('.nav-link').on('click', function() {
1339    if ((nc(this).attr('href') === '#shipping' && nc(this).hasClass('active'))){
1340        //alert('dddd');
1341        //calling_getwebcheckoutinfo();
1342    }
1343});*/
1344
1345//edit-cart
1346nc('.edit-cart').on('click', function(e){
1347    e.preventDefault();
1348    var tab_val = nc(this).attr("data-id");
1349	
1350	//activate next tab
1351	var next_tab = nc('.nav a.active').parent('li').next('li').find('a');
1352	if(next_tab.length > 0){
1353	  nc('.nav a[href="#'+ tab_val +'"]').tab('show');
1354	}
1355});
1356
1357//Edit Customer
1358nc('#chkout_customer_btn').on('click', function(){       
1359    jQuery('.nav a[href="#delivery-checkout"]').tab('show');        
1360});
1361
1362//Edit Shipping.
1363nc('#chkout_shipping_btn').on('click', function(){        
1364    jQuery('.nav a[href="#delivery-checkout"]').tab('show');        
1365});
1366
1367//Edit Pickup.
1368nc('#chkout_pickup_btn').on('click', function(){        
1369    jQuery('.nav a[href="#delivery-checkout"]').tab('show');        
1370});
1371
1372//Edit Delivery.
1373nc('#chkout_delivery_btn').on('click', function(){        
1374    jQuery('.nav a[href="#delivery-checkout"]').tab('show');        
1375});
1376
1377//Edit Message.
1378nc('#chkout_message_btn').on('click', function(){        
1379    jQuery('.nav a[href="#delivery-checkout"]').tab('show');        
1380});
1381
1382//Edit Payment
1383nc('#chkout_payment_btn').on('click', function(){        
1384    jQuery('.nav a[href="#payreview-checkout"]').tab('show');
1385    jQuery('#review-checkout-sec').hide();
1386    jQuery('#pay-checkout-sec').show();
1387});
1388
1389//Auto copy Customer names to ship name and pickup name.
1390nc('#first-name,#shipfirstname').on('keyup', function(){
1391    var cfn = jQuery(this).val();
1392    jQuery('#shipfirstname,#pickupfirstname,#delifirstname').empty().val(cfn);
1393});
1394
1395nc('#last-name,#shiplastname').on('keyup', function(){
1396    var cln = jQuery(this).val();
1397    jQuery('#shiplastname,#pickuplastname,#delilastname').empty().val(cln);
1398});
1399
1400//Auto copy email address ship to delivery
1401nc('#shipemail').on('keyup', function(){
1402    var cem = jQuery(this).val();
1403    jQuery('#deliemail,#pickupemail').empty().val(cem);
1404});
1405
1406//update email delviery section email field if user type email address on username
1407nc('#user-name').on('keyup', function () {
1408    var usname = nc(this).val();
1409    var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
1410
1411    if (emailPattern.test(usname)) {
1412        nc('#shipemail, #deliemail, #pickupemail').val(usname);
1413    }
1414});
1415
1416//Get Selected Pickup Location
1417nc('#checkout_pickuplocation').change(function() {
1418    var pickuplocation_name=jQuery('#checkout_pickuplocation').find(":selected").val();
1419    var pickuplocation_address=jQuery('#checkout_pickuplocation').find(":selected").data('address');
1420    var pickuplocation_city=jQuery('#checkout_pickuplocation').find(":selected").data('city');
1421    var pickuplocation_state=jQuery('#checkout_pickuplocation').find(":selected").data('state');
1422    var pickuplocation_zipcode=jQuery('#checkout_pickuplocation').find(":selected").data('zipcode');
1423    var pickuplocation_phone=jQuery('#checkout_pickuplocation').find(":selected").data('phone');
1424
1425    // Change content    
1426    nc("#display_checkout_pickuplocation #pickuplocation_name").text(pickuplocation_name);
1427    nc("#display_checkout_pickuplocation #pickup_location_address").text(pickuplocation_address+' '+pickuplocation_city+' '+pickuplocation_state+' '+pickuplocation_zipcode);
1428    nc("#display_checkout_pickuplocation #pickuplocation_phone").text(pickuplocation_phone);
1429    nc("#display_checkout_pickuplocation").show(); 
1430});
1431
1432//Hide/show gift-card-sec
1433nc('#redeem-gift-card').on('click', function(){
1434    if(jQuery("#redeem-gift-card").is(':checked')){
1435        jQuery("#gift-card-sec").show();
1436    } else {
1437        jQuery("#gift-card-sec").hide();
1438    }        
1439});
1440
1441//hide/show loyal-point-sec
1442nc('#redeem-loyal-point').on('click', function(){
1443    if(jQuery("#redeem-loyal-point").is(':checked')){
1444        jQuery("#loyal-point-sec").show();
1445    } else {
1446        jQuery("#loyal-point-sec").hide();
1447    }        
1448});
1449
1450//Check if the security code is not null.
1451nc('#security-code').on('keyup', function() {
1452    if (nc(this).val().trim() === '') {
1453        nc('#gift-card-redeem-btn').html('<i class="fa fa-check me-2"></i> Check Balance');
1454    }
1455});
1456
1457//Review / Redeem Gift Card
1458nc(document).on('click', '.redeem-btn', function(){
1459    event.preventDefault();
1460    
1461    var gift_card_num  = nc("#gift-card-num").val();
1462    var security_code  = nc("#security-code").val();
1463
1464    //validation empty field 
1465    var errors = 0;
1466    nc('#gift-card-sec :input[data-required = "yes"]').map(function(){
1467        if( !nc(this).val().trim()) {
1468            nc(this).addClass('error');
1469            errors++;
1470        } else if (nc(this).val()) {
1471            nc(this).removeClass('error');
1472        }   
1473    });
1474
1475    //Empty field validation.
1476    if(errors > 0){
1477        //nc('#errorwarn_gif').show();
1478        //nc('#errorwarn_gif').html("Please fill the required fields.");
1479        return false;
1480        
1481    }else{
1482        //nc('#errorwarn_gif').hide('slow'); //hide error warning.
1483        nc.ajax({
1484            type: "POST",
1485            url:""+nc('#admin_url').val()+"", 
1486           data: {
1487                action: "customize_redeem_gift_card",
1488                result: "redeem_giftcard",
1489                gift_card_num : gift_card_num,
1490                security_code : security_code,
1491            },
1492            beforeSend: function(){
1493                nc('#gift-card-redeem-btn').html('<i style="font-size: 16px;" class="fa fa-circle-thin me-2"></i>Loading...');
1494            },
1495            success: function(data){
1496                var splitted = data.split('===');
1497                if(data){
1498                    console.log(data);
1499                    if(splitted[1] > 0){
1500                        var bal = parseFloat(splitted[1]).toFixed(2);
1501                        nc('#gift-card-redeem-btn').empty().html('<i class="fa fa-check me-2"></i> Redeem').removeClass('redeem-btn').addClass('redeem-now');
1502                        nc('.giftcard-result').show().empty().html('The Gift Card has a balance of <b>$'+bal+'</b> that can be applied to this order.');
1503                        nc('#gifcrd_id').val(splitted[2]);
1504                        nc('#gifcrd_bal').val(bal);
1505                    }else{
1506                        nc('#gift-card-redeem-btn').empty().html('<i class="fa fa-check me-2"></i> Check Balance');
1507                        nc('.giftcard-result').show().empty().html('<span id="errorwarn">'+splitted[0]+'</span>');
1508                    }
1509                } 
1510            }
1511        });
1512    }       
1513});
1514
1515//Redeem now
1516nc(document).on('click', '.redeem-now', function(){
1517    event.preventDefault();
1518    var gift_card_chk  = nc("#redeem-gift-card").prop("checked") ? nc("#redeem-gift-card").val() : ""; //Yes
1519    var reward_chk     = nc("#redeem-loyal-point").prop("checked") ? nc("#redeem-loyal-point").val() : 0;
1520    
1521    var islogin        = nc('#hid_isloggedin').val(); //check is login.
1522    
1523    if (islogin && islogin === "1") {
1524        var customer_type = 'Login';
1525    }else{
1526        var customer_type = 'Guest';
1527    }
1528    
1529    var delivery_type   = nc('#delivery-checkout .nav-item .nav-link.active').attr('data-delivery');
1530    var discountcode    = nc('#discount-code').val();
1531    var token           = nc("#hid_vaultid").val(); //token taken from hidden after updating
1532    var creditcardtype  = nc("#hid_creditcardtype").val(); //card type taken from hidden after adding creditcard.
1533    
1534    //Shipping
1535    var shipfirstname   = nc("#shipfirstname").val();
1536    var shiplastname    = nc("#shiplastname").val();
1537    var shipemail       = nc("#shipemail").val();
1538    var shipbirthdate   = nc("#shipbirthdate").val();
1539    var shipcompanyname = nc("#shipcompanyname").val();
1540    var shipaddress1    = nc("#shipaddress1").val();
1541    var shipaddress2    = nc("#shipaddress2").val();
1542    var shippostalcode  = nc("#shippostalcode").val();
1543    var shipcity        = nc("#shipcity").val();
1544    var shipstate       = nc("#shipstate").val();
1545    var shipphone       = nc("#shipphone").val();
1546    var shippingoption  = nc("#shipping-option").val(); //service
1547    var shippingmethod  = nc("#shipping-method").val(); //method
1548    var isgift          = nc("#isgift").prop("checked") ? nc("#isgift").val() : "";
1549    var giftnotes       = nc("#giftnotes").val();
1550    var emailaddress2   = nc("#emailaddress2").val();
1551    var notes           = nc("#notes").val();
1552
1553    //pickup 
1554    var pickupfirstname = nc("#pickupfirstname").val();
1555    var pickuplastname  = nc("#pickuplastname").val();
1556    var pickupemail     = nc("#pickupemail").val();  
1557    var birthdate       = nc("#birthdate").val();
1558    var checkout_pickuplocation = nc("#checkout_pickuplocation").val();
1559    
1560    //delivery
1561    var delifirstname   = nc("#delifirstname").val();
1562    var delilastname    = nc("#delilastname").val();
1563    var deliemail       = nc("#deliemail").val();
1564    var delicompanyname = nc("#delicompanyname").val();
1565    var deliaddress1    = nc("#deliaddress1").val();
1566    var deliaddress2    = nc("#deliaddress2").val();
1567    var delipostalcode  = nc("#delipostalcode").val();
1568    var delicity        = nc("#delicity").val();
1569    var delistate       = nc("#delistate").val();
1570    var deliphone       = nc("#deliphone").val();
1571    
1572    //PAYMENT/REVIEW
1573    var gift_card_num    = nc("#gift-card-num").val();
1574    var security_code    = nc("#security-code").val();
1575    var giftcard_id      = nc("#gifcrd_id").val();
1576    var giftcard_bal     = nc("#gifcrd_bal").val();
1577    var useloyaltypoints = (nc("#redeem-loyal-point").prop("checked") && nc("#is-loyal-redeemed").val() == 'Yes') ? nc("#redeem-loyal-point").val() : 0; // send 1, only when redeem is active.
1578    
1579    var creditcardnum   = nc("#hid_creditcardnum").val();
1580    var expitationmonth = nc("#hid_expirationmonth").val();
1581    var expitationyear  = nc("#hid_expirationyear").val();
1582    //var creditcardcvv2  = nc("#creditcardcvv2").val();
1583    var avsaddress      = nc("#avsaddress").val();
1584    var avspostalcode   = nc("#avspostalcode").val();
1585    var avscity         = nc("#avscity").val();
1586    var avsstate        = nc("#avsstate").val();
1587    var allocation_id   = nc("#allocation_id").val();
1588    
1589    //validation empty field 
1590    var errors = 0;
1591    nc('#gift-card-sec :input[data-required = "yes"]').map(function(){
1592        if(!nc(this).val().trim()) {
1593            nc(this).addClass('error');
1594            errors++;
1595        } else if (nc(this).val()) {
1596            nc(this).removeClass('error');
1597        }   
1598    });
1599
1600    //Empty field validation.
1601    if(errors > 0){
1602        return false;
1603    }else{
1604        nc.ajax({
1605            type: "POST",
1606            url:""+nc('#admin_url').val()+"", 
1607           data: {
1608                action: "customize_redeem_now",
1609                result: "gift_redeem_now",
1610                useloyaltypoints: useloyaltypoints,
1611                giftcard_id     : giftcard_id, //important
1612                giftcard_bal    : giftcard_bal, //important
1613                gift_card_chk   : gift_card_chk, //important
1614                reward_chk      : reward_chk, //important
1615                delivery_type   : delivery_type,
1616                customer_type   : customer_type,
1617                discountcode    : discountcode,
1618                token           : token,
1619                creditcardtype  : creditcardtype,
1620                shipfirstname   : shipfirstname,
1621                shiplastname    : shiplastname,
1622                shipemail       : shipemail,
1623                shipbirthdate   : shipbirthdate,
1624                shipcompanyname : shipcompanyname,
1625                shipaddress1    : shipaddress1,
1626                shipaddress2    : shipaddress2,
1627                shippostalcode  : shippostalcode,
1628                shipcity        : shipcity,
1629                shipstate       : shipstate,
1630                shipphone       : shipphone,
1631                shippingoption  : shippingoption,
1632                shippingmethod  : shippingmethod,
1633                isgift          : isgift,
1634                giftnotes       : giftnotes, //no element
1635                emailaddress2   : emailaddress2,
1636                notes           : notes,
1637                pickupfirstname : pickupfirstname,
1638                pickuplastname  : pickuplastname,
1639                pickupemail     : pickupemail,
1640                birthdate       : birthdate,
1641                checkout_pickuplocation : checkout_pickuplocation,
1642                delifirstname   : delifirstname,
1643                delilastname    : delilastname,
1644                deliemail       : deliemail,
1645                delicompanyname : delicompanyname,
1646                deliaddress1    : deliaddress1,
1647                deliaddress2    : deliaddress2,
1648                delipostalcode  : delipostalcode,
1649                delicity        : delicity,
1650                delistate       : delistate,
1651                deliphone       : deliphone,
1652                gift_card_num   : gift_card_num,
1653                security_code   : security_code,
1654                creditcardnum   : creditcardnum,
1655                expitationmonth : expitationmonth,
1656                expitationyear  : expitationyear,
1657                //creditcardcvv2 : creditcardcvv2,
1658                avsaddress      : avsaddress,
1659                avspostalcode   : avspostalcode,
1660                avscity         : avscity,
1661                avsstate        : avsstate,
1662                allocation_id   : allocation_id,
1663            },
1664            beforeSend: function(){
1665                nc('#gift-card-redeem-btn').html('<i style="font-size: 16px;" class="fa fa-circle-thin me-2"></i>Loading...');
1666            },
1667            success: function(data){
1668                var splitted = data.split('===');
1669                console.log(splitted); 
1670                
1671                var subtotal = parseFloat(splitted[1]).toFixed(2);
1672                var discount = parseFloat(splitted[2]).toFixed(2);
1673                var deliveryfee = parseFloat(splitted[3]).toFixed(2);
1674                var tax = parseFloat(splitted[4]).toFixed(2);
1675                var total = parseFloat(splitted[5]).toFixed(2);
1676                var gift = parseFloat(splitted[6]).toFixed(2);
1677                var reward = parseFloat(splitted[7]).toFixed(2);
1678                
1679                nc(".sidebar_inventory_list").empty().html(splitted[0]);
1680                nc(".basket_subtotal").empty().html('$' + subtotal);
1681                nc(".basket_total").empty().html('$'+total);
1682                
1683                if (discount > 0) {
1684                    nc(".disc-con").removeClass('d-none').addClass('d-flex');
1685                    nc(".basket_discount").empty().html('$' + discount);
1686                } else {
1687                    nc(".disc-con").removeClass('d-flex').addClass('d-none');
1688                }
1689                
1690                if (deliveryfee > 0) {
1691                    nc(".deli-con").removeClass('d-none').addClass('d-flex');
1692                    nc(".basket_del_fee").empty().html('$' + deliveryfee);
1693                } else {
1694                    nc(".deli-con").removeClass('d-flex').addClass('d-none');
1695                }
1696                
1697                if (tax > 0) {
1698                    nc(".tax-con").removeClass('d-none').addClass('d-flex');
1699                    nc(".basket_tax").empty().html('$' + tax);
1700                } else {
1701                    nc(".tax-con").removeClass('d-flex').addClass('d-none');
1702                }
1703                
1704                //If GiftCardAmount is not empty
1705                if(gift > 0){
1706                    nc(".giftcard-con").removeClass('d-none').addClass('d-flex');
1707                    nc(".basket_gift").empty().html('$' + gift);
1708                    
1709                    nc('#gift-card-redeem-btn').empty().html('<i class="fa fa-check me-2"></i> Redeemed').removeClass('redeem-now').addClass('redeem-btn');
1710                    nc(".giftcard-result").empty().html('<b>$'+gift+'</b> has been applied to this order.');
1711                    nc('#is-gift-redeemed').val('Yes');
1712                }else{
1713                    nc(".giftcard-con").removeClass('d-flex').addClass('d-none');
1714                    nc('#is-gift-redeemed').val('No');
1715                }
1716                
1717                //if reward is not empty
1718                if(reward > 0){
1719                    nc(".rewards-con").removeClass('d-none').addClass('d-flex');
1720                    nc(".basket_reward").empty().html('$' + reward);
1721                }else{
1722                    nc(".rewards-con").removeClass('d-flex').addClass('d-none');
1723                }
1724                
1725                //if basket due total is 0.00 and gift card balance not 0.00, remove credit card validation 
1726                if (parseFloat(total) === 0.00 && parseFloat(gift) !== 0.00) {
1727                    jQuery("#creditcardnum, #expirationmonth, #expirationyear").attr("data-required", "no");
1728                } else {
1729                    jQuery("#creditcardnum, #expirationmonth, #expirationyear").attr("data-required", "yes");
1730                }
1731            }
1732        });
1733    }       
1734});
1735
1736//Loyalty point Redeem
1737nc(document).on('click', '#loyal-redeem-btn', function(){
1738    event.preventDefault();
1739    var gift_card_chk  = nc("#redeem-gift-card").prop("checked") ? nc("#redeem-gift-card").val() : ""; //Yes
1740    var reward_chk     = nc("#redeem-loyal-point").prop("checked") ? nc("#redeem-loyal-point").val() : 0; 
1741    
1742    var islogin        = nc('#hid_isloggedin').val(); //check is login.
1743    
1744    if (islogin && islogin === "1") {
1745        var customer_type = 'Login';
1746    }else{
1747        var customer_type = 'Guest';
1748    }
1749    
1750    var delivery_type   = nc('#delivery-checkout .nav-item .nav-link.active').attr('data-delivery');
1751    var discountcode    = nc('#discount-code').val();
1752    var token           = nc("#hid_vaultid").val(); //token taken from hidden after updating
1753    var creditcardtype  = nc("#hid_creditcardtype").val(); //card type taken from hidden after adding creditcard.
1754    
1755    //Shipping
1756    var shipfirstname   = nc("#shipfirstname").val();
1757    var shiplastname    = nc("#shiplastname").val();
1758    var shipemail       = nc("#shipemail").val();
1759    var shipbirthdate   = nc("#shipbirthdate").val();
1760    var shipcompanyname = nc("#shipcompanyname").val();
1761    var shipaddress1    = nc("#shipaddress1").val();
1762    var shipaddress2    = nc("#shipaddress2").val();
1763    var shippostalcode  = nc("#shippostalcode").val();
1764    var shipcity        = nc("#shipcity").val();
1765    var shipstate       = nc("#shipstate").val();
1766    var shipphone       = nc("#shipphone").val();
1767    var shippingoption  = nc("#shipping-option").val(); //service
1768    var shippingmethod  = nc("#shipping-method").val(); //method
1769    var isgift          = nc("#isgift").prop("checked") ? nc("#isgift").val() : "";
1770    var giftnotes       = nc("#giftnotes").val();
1771    var emailaddress2   = nc("#emailaddress2").val();
1772    var notes           = nc("#notes").val();
1773
1774    //pickup 
1775    var pickupfirstname = nc("#pickupfirstname").val();
1776    var pickuplastname  = nc("#pickuplastname").val();
1777    var pickupemail     = nc("#pickupemail").val();  
1778    var birthdate       = nc("#birthdate").val();
1779    var checkout_pickuplocation = nc("#checkout_pickuplocation").val();
1780    
1781    //delivery
1782    var delifirstname   = nc("#delifirstname").val();
1783    var delilastname    = nc("#delilastname").val();
1784    var deliemail       = nc("#deliemail").val();
1785    var delicompanyname = nc("#delicompanyname").val();
1786    var deliaddress1    = nc("#deliaddress1").val();
1787    var deliaddress2    = nc("#deliaddress2").val();
1788    var delipostalcode  = nc("#delipostalcode").val();
1789    var delicity        = nc("#delicity").val();
1790    var delistate       = nc("#delistate").val();
1791    var deliphone       = nc("#deliphone").val();
1792    
1793    //PAYMENT/REVIEW
1794    var gift_card_num    = nc("#gift-card-num").val();
1795    var security_code    = nc("#security-code").val();
1796    var giftcard_id      = nc("#gifcrd_id").val();
1797    var giftcard_bal     = nc("#gifcrd_bal").val();
1798    //var useloyaltypoints = nc("#redeem-loyal-point").prop("checked") ? nc("#redeem-loyal-point").val() : 0;
1799    
1800    var creditcardnum   = nc("#hid_creditcardnum").val();
1801    var expitationmonth = nc("#hid_expirationmonth").val();
1802    var expitationyear  = nc("#hid_expirationyear").val();
1803    //var creditcardcvv2  = nc("#creditcardcvv2").val();
1804    var avsaddress      = nc("#avsaddress").val();
1805    var avspostalcode   = nc("#avspostalcode").val();
1806    var avscity         = nc("#avscity").val();
1807    var avsstate        = nc("#avsstate").val();
1808    
1809    //validation empty field 
1810    var errors = 0;
1811    nc('#loyal-point-sec :input[data-required = "yes"]').map(function(){
1812        if( !nc(this).val().trim()) {
1813            nc(this).addClass('error');
1814            errors++;
1815        } else if (nc(this).val()) {
1816            nc(this).removeClass('error');
1817        }   
1818    });
1819
1820    //Empty field validation.
1821    if(errors > 0){
1822        return false;
1823    }else{
1824        nc.ajax({
1825            type: "POST",
1826            url:""+nc('#admin_url').val()+"", 
1827           data: {
1828                action: "customize_redeem_now",
1829                result: "loyal_redeem_now",
1830                useloyaltypoints  : 1, //important
1831                gift_card_chk   : gift_card_chk, //important
1832                reward_chk      : reward_chk, //important
1833                giftcard_id     : giftcard_id,
1834                giftcard_bal    : giftcard_bal,
1835                delivery_type   : delivery_type,
1836                customer_type   : customer_type,
1837                discountcode    : discountcode,
1838                token           : token,
1839                creditcardtype  : creditcardtype,
1840                shipfirstname   : shipfirstname,
1841                shiplastname    : shiplastname,
1842                shipemail       : shipemail,
1843                shipbirthdate   : shipbirthdate,
1844                shipcompanyname : shipcompanyname,
1845                shipaddress1    : shipaddress1,
1846                shipaddress2    : shipaddress2,
1847                shippostalcode  : shippostalcode,
1848                shipcity        : shipcity,
1849                shipstate       : shipstate,
1850                shipphone       : shipphone,
1851                shippingoption  : shippingoption,
1852                shippingmethod  : shippingmethod,
1853                isgift          : isgift,
1854                giftnotes       : giftnotes, //no element
1855                emailaddress2   : emailaddress2,
1856                notes           : notes,
1857                pickupfirstname : pickupfirstname,
1858                pickuplastname  : pickuplastname,
1859                pickupemail     : pickupemail,
1860                birthdate       : birthdate,
1861                checkout_pickuplocation : checkout_pickuplocation,
1862                delifirstname   : delifirstname,
1863                delilastname    : delilastname,
1864                deliemail       : deliemail,
1865                delicompanyname : delicompanyname,
1866                deliaddress1    : deliaddress1,
1867                deliaddress2    : deliaddress2,
1868                delipostalcode  : delipostalcode,
1869                delicity        : delicity,
1870                delistate       : delistate,
1871                deliphone       : deliphone,
1872                gift_card_num   : gift_card_num,
1873                security_code   : security_code,
1874                creditcardnum   : creditcardnum,
1875                expitationmonth : expitationmonth,
1876                expitationyear  : expitationyear,
1877                //creditcardcvv2 : creditcardcvv2,
1878                avsaddress      : avsaddress,
1879                avspostalcode   : avspostalcode,
1880                avscity         : avscity,
1881                avsstate        : avsstate,
1882            },
1883            beforeSend: function(){
1884                nc('#loyal-redeem-btn').html('<i style="font-size: 16px;" class="fa fa-circle-thin me-2"></i>Loading...');
1885            },
1886            success: function(data){
1887                var splitted = data.split('===');
1888                if(data){
1889                    console.log(data);
1890                    
1891                    var subtotal = parseFloat(splitted[1]).toFixed(2);
1892                    var discount = parseFloat(splitted[2]).toFixed(2);
1893                    var deliveryfee = parseFloat(splitted[3]).toFixed(2);
1894                    var tax = parseFloat(splitted[4]).toFixed(2);
1895                    var total = parseFloat(splitted[5]).toFixed(2);
1896                    var gift = parseFloat(splitted[6]).toFixed(2);
1897                    var reward = parseFloat(splitted[7]).toFixed(2);
1898                    
1899                    nc(".sidebar_inventory_list").empty().html(splitted[0]);
1900                    nc(".basket_subtotal").empty().html('$' + subtotal);
1901                    nc(".basket_total").empty().html('$'+total);
1902                    
1903                    if (discount > 0) {
1904                        nc(".disc-con").removeClass('d-none').addClass('d-flex');
1905                        nc(".basket_discount").empty().html('$' + discount);
1906                    } else {
1907                        nc(".disc-con").removeClass('d-flex').addClass('d-none');
1908                    }
1909                    
1910                    if (deliveryfee > 0) {
1911                        nc(".deli-con").removeClass('d-none').addClass('d-flex');
1912                        nc(".basket_del_fee").empty().html('$' + deliveryfee);
1913                    } else {
1914                        nc(".deli-con").removeClass('d-flex').addClass('d-none');
1915                    }
1916                    
1917                    if (tax > 0) {
1918                        nc(".tax-con").removeClass('d-none').addClass('d-flex');
1919                        nc(".basket_tax").empty().html('$' + tax);
1920                    } else {
1921                        nc(".tax-con").removeClass('d-flex').addClass('d-none');
1922                    }
1923                    
1924                    //If GiftCardAmount is not empty
1925                    if(gift > 0){
1926                        nc(".giftcard-con").removeClass('d-none').addClass('d-flex');
1927                        nc(".basket_gift").empty().html('$' + gift);
1928                    }else{
1929                        nc(".giftcard-con").removeClass('d-flex').addClass('d-none');
1930                    }
1931                    
1932                    //if reward is not empty
1933                    if(reward > 0){
1934                        nc(".rewards-con").removeClass('d-none').addClass('d-flex');
1935                        nc(".basket_reward").empty().html('$' + reward);
1936                        
1937                        //Redeem message
1938                        nc('#loyal-redeem-btn').empty().html('<i class="fa fa-check me-2"></i> Redeemed');
1939                        nc('.loyalty-result').show().empty().html('<b>$'+reward+'</b> of your Rewards have been applied to this order.');
1940                        nc('#is-loyal-redeemed').val('Yes');
1941                    
1942                    }else{
1943                        nc(".rewards-con").removeClass('d-flex').addClass('d-none');
1944                        
1945                        //Redeem message
1946                        nc('#loyal-redeem-btn').empty().html('<i class="fa fa-check me-2"></i> Redeem');
1947                        nc('.loyalty-result').show().empty().html('You have <b>$'+reward+'</b> Rewards balance.');
1948                        nc('#is-loyal-redeemed').val('No');
1949                    }
1950                } 
1951            }
1952        });
1953    }
1954});
1955
1956//Coupon Discount
1957nc(document).on('click', '.coupon-btn', function(){
1958    event.preventDefault();
1959    var gift_card_chk  = nc("#redeem-gift-card").prop("checked") ? nc("#redeem-gift-card").val() : ""; //Yes
1960    var reward_chk     = nc("#redeem-loyal-point").prop("checked") ? nc("#redeem-loyal-point").val() : 0; 
1961    
1962    var islogin         = nc('#hid_isloggedin').val(); //check is login.
1963    
1964    if (islogin && islogin === "1") {
1965        var customer_type = 'Login';
1966    }else{
1967        var customer_type = 'Guest';
1968    }
1969    
1970    var delivery_type   = nc('#delivery-checkout .nav-item .nav-link.active').attr('data-delivery');
1971    var discountcode    = nc('#discount-code').val();
1972    var token           = nc("#hid_vaultid").val(); //token taken from hidden after updating
1973    var creditcardtype  = nc("#hid_creditcardtype").val(); //card type taken from hidden after adding creditcard.
1974    
1975    //Shipping
1976    var shipfirstname   = nc("#shipfirstname").val();
1977    var shiplastname    = nc("#shiplastname").val();
1978    var shipemail       = nc("#shipemail").val();
1979    var shipbirthdate   = nc("#shipbirthdate").val();
1980    var shipcompanyname = nc("#shipcompanyname").val();
1981    var shipaddress1    = nc("#shipaddress1").val();
1982    var shipaddress2    = nc("#shipaddress2").val();
1983    var shippostalcode  = nc("#shippostalcode").val();
1984    var shipcity        = nc("#shipcity").val();
1985    var shipstate       = nc("#shipstate").val();
1986    var shipphone       = nc("#shipphone").val();
1987    var shippingoption  = nc("#shipping-option").val(); //service
1988    var shippingmethod  = nc("#shipping-method").val(); //method
1989    var isgift          = nc("#isgift").prop("checked") ? nc("#isgift").val() : "";
1990    var giftnotes       = nc("#giftnotes").val();
1991    var emailaddress2   = nc("#emailaddress2").val();
1992    var notes           = nc("#notes").val();
1993
1994    //pickup 
1995    var pickupfirstname = nc("#pickupfirstname").val();
1996    var pickuplastname  = nc("#pickuplastname").val();
1997    var pickupemail     = nc("#pickupemail").val();  
1998    var birthdate       = nc("#birthdate").val();
1999    var checkout_pickuplocation = nc("#checkout_pickuplocation").val();
2000    
2001    //delivery
2002    var delifirstname   = nc("#delifirstname").val();
2003    var delilastname    = nc("#delilastname").val();
2004    var deliemail       = nc("#deliemail").val();
2005    var delicompanyname = nc("#delicompanyname").val();
2006    var deliaddress1    = nc("#deliaddress1").val();
2007    var deliaddress2    = nc("#deliaddress2").val();
2008    var delipostalcode  = nc("#delipostalcode").val();
2009    var delicity        = nc("#delicity").val();
2010    var delistate       = nc("#delistate").val();
2011    var deliphone       = nc("#deliphone").val();
2012    
2013    //PAYMENT/REVIEW
2014    var gift_card_num    = nc("#gift-card-num").val();
2015    var security_code    = nc("#security-code").val();
2016    var giftcard_id      = nc("#gifcrd_id").val();
2017    var giftcard_bal     = nc("#gifcrd_bal").val();
2018    var useloyaltypoints = nc("#redeem-loyal-point").prop("checked") ? nc("#redeem-loyal-point").val() : 0;
2019    
2020    var creditcardnum   = nc("#hid_creditcardnum").val();
2021    var expitationmonth = nc("#hid_expirationmonth").val();
2022    var expitationyear  = nc("#hid_expirationyear").val();
2023    //var creditcardcvv2  = nc("#creditcardcvv2").val();
2024    var avsaddress      = nc("#avsaddress").val();
2025    var avspostalcode   = nc("#avspostalcode").val();
2026    var avscity         = nc("#avscity").val();
2027    var avsstate        = nc("#avsstate").val();
2028
2029    //validation empty field 
2030    var errors = 0;
2031    nc('.discount-container :input[data-required = "yes"]').map(function(){
2032        if( !nc(this).val().trim()) {
2033            nc(this).addClass('error');
2034            errors++;
2035        } else if (nc(this).val()) {
2036            nc(this).removeClass('error');
2037        }   
2038    });
2039
2040    //Empty field validation.
2041    if(errors > 0){
2042        return false;
2043    }else{
2044        nc.ajax({
2045            type: "POST",
2046            url:""+nc('#admin_url').val()+"", 
2047           data: {
2048                action: "customize_redeem_now",
2049                result: "discount_now",
2050                useloyaltypoints  : useloyaltypoints,
2051                gift_card_chk   : gift_card_chk, //important
2052                reward_chk      : reward_chk, //important
2053                giftcard_id     : giftcard_id,
2054                giftcard_bal    : giftcard_bal,
2055                delivery_type   : delivery_type,
2056                customer_type   : customer_type,
2057                discountcode    : discountcode,
2058                token           : token,
2059                creditcardtype  : creditcardtype,
2060                shipfirstname   : shipfirstname,
2061                shiplastname    : shiplastname,
2062                shipemail       : shipemail,
2063                shipbirthdate   : shipbirthdate,
2064                shipcompanyname : shipcompanyname,
2065                shipaddress1    : shipaddress1,
2066                shipaddress2    : shipaddress2,
2067                shippostalcode  : shippostalcode,
2068                shipcity        : shipcity,
2069                shipstate       : shipstate,
2070                shipphone       : shipphone,
2071                shippingoption  : shippingoption,
2072                shippingmethod  : shippingmethod,
2073                isgift          : isgift,
2074                giftnotes       : giftnotes, //no element
2075                emailaddress2   : emailaddress2,
2076                notes           : notes,
2077                pickupfirstname : pickupfirstname,
2078                pickuplastname  : pickuplastname,
2079                pickupemail     : pickupemail,
2080                birthdate       : birthdate,
2081                checkout_pickuplocation : checkout_pickuplocation,
2082                delifirstname   : delifirstname,
2083                delilastname    : delilastname,
2084                deliemail       : deliemail,
2085                delicompanyname : delicompanyname,
2086                deliaddress1    : deliaddress1,
2087                deliaddress2    : deliaddress2,
2088                delipostalcode  : delipostalcode,
2089                delicity        : delicity,
2090                delistate       : delistate,
2091                deliphone       : deliphone,
2092                gift_card_num   : gift_card_num,
2093                security_code   : security_code,
2094                creditcardnum   : creditcardnum,
2095                expitationmonth : expitationmonth,
2096                expitationyear  : expitationyear,
2097                //creditcardcvv2 : creditcardcvv2,
2098                avsaddress      : avsaddress,
2099                avspostalcode   : avspostalcode,
2100                avscity         : avscity,
2101                avsstate        : avsstate,
2102            },
2103            beforeSend: function(){
2104                nc('.coupon-btn').html('<i style="font-size: 14px;" class="fa fa-circle-thin me-2"></i>Loading...');
2105            },
2106            success: function(data){
2107                var splitted = data.split('===');
2108                if(data){
2109                    console.log(data);
2110                    
2111                    if(splitted[8] > 0){ //If StatusCode not 0.
2112                        nc('.coupon-btn').empty().html('<i style="font-size: 14px;" class="fa fa-check me-2"></i>Applied');
2113                        nc('#errorwarn_discode').empty();
2114                        
2115                        var subtotal = parseFloat(splitted[1]).toFixed(2);
2116                        var discount = parseFloat(splitted[2]).toFixed(2);
2117                        var deliveryfee = parseFloat(splitted[3]).toFixed(2);
2118                        var tax = parseFloat(splitted[4]).toFixed(2);
2119                        var total = parseFloat(splitted[5]).toFixed(2);
2120                        var gift = parseFloat(splitted[6]).toFixed(2);
2121                        var reward = parseFloat(splitted[7]).toFixed(2);
2122                        
2123                        nc(".sidebar_inventory_list").empty().html(splitted[0]);
2124                        nc(".basket_subtotal").empty().html('$' + subtotal);
2125                        nc(".basket_total").empty().html('$'+total);
2126                        
2127                        if (discount > 0) {
2128                            nc(".disc-con").removeClass('d-none').addClass('d-flex');
2129                            nc(".basket_discount").empty().html('$' + discount);
2130                        } else {
2131                            nc(".disc-con").removeClass('d-flex').addClass('d-none');
2132                        }
2133                        
2134                        if (deliveryfee > 0) {
2135                            nc(".deli-con").removeClass('d-none').addClass('d-flex');
2136                            nc(".basket_del_fee").empty().html('$' + deliveryfee);
2137                        } else {
2138                            nc(".deli-con").removeClass('d-flex').addClass('d-none');
2139                        }
2140                        
2141                        if (tax > 0) {
2142                            nc(".tax-con").removeClass('d-none').addClass('d-flex');
2143                            nc(".basket_tax").empty().html('$' + tax);
2144                        } else {
2145                            nc(".tax-con").removeClass('d-flex').addClass('d-none');
2146                        }
2147                        
2148                        //If GiftCardAmount is not empty
2149                        if(gift > 0){
2150                            nc(".giftcard-con").removeClass('d-none').addClass('d-flex');
2151                            nc(".basket_gift").empty().html('$' + gift);
2152                        }else{
2153                            nc(".giftcard-con").removeClass('d-flex').addClass('d-none');
2154                        }
2155                        
2156                        //if reward is not empty
2157                        if(reward > 0){
2158                            nc(".rewards-con").removeClass('d-none').addClass('d-flex');
2159                            nc(".basket_reward").empty().html('$' + reward);
2160                        }else{
2161                            nc(".rewards-con").removeClass('d-flex').addClass('d-none');
2162                        }
2163                    
2164                    }else{
2165                        nc('.coupon-btn').empty().html('<i style="font-size: 14px;" class="fa fa-check me-2"></i>Apply');
2166                        nc('#errorwarn_discode').empty().html(splitted[9]);
2167                    } 
2168                } 
2169            }
2170        });
2171    }
2172});
2173
2174
2175//validate ship phone 
2176function validateDeliPhoneNumber(phoneNumber) {
2177    // Define the regular expression for the desired format
2178    var phoneRegex = /^\d{3}-\d{3}-\d{4}$/;
2179    // Test the phone number against the regular expression
2180    return phoneRegex.test(phoneNumber);
2181}
2182
2183//Validate Pickup Phone field and  to phone format
2184nc('#deliphone').on('blur',function(){
2185    var pickupphone = jQuery('#deliphone').val();
2186    var maxCount = jQuery('#deliphone').attr('maxlength');
2187    
2188    //var isValid = validateDeliPhoneNumber(pickupphone);
2189    var onlynumber = pickupphone.replace(/\D/g, ''); // Remove non-numeric characters
2190    var isValid = onlynumber.length; //validateDeliPhoneNumber(pickupphone);
2191    var numbers = '';
2192
2193    if (isValid > 12) {               
2194           jQuery('#errorwarn_deliphone').hide();
2195    } else {
2196
2197       if( pickupphone.length > 0 ){
2198            var numbers = pickupphone.replace(/\D/g, ''); // Remove non-numeric characters
2199            // Format the number as XXX-XXX-XXXX
2200            if (numbers.length >= 3) {
2201                numbers = numbers.substring(0, 3) + '-' + numbers.substring(3);
2202            }
2203            if (numbers.length >= 7) {
2204                numbers = numbers.substring(0, 7) + '-' + numbers.substring(7);
2205            }         
2206            //Converted phone display into input field
2207            jQuery('#deliphone').val(numbers);
2208            //After change format check validation
2209            var isValid_new = validateDeliPhoneNumber(numbers);
2210            if (isValid_new) {                
2211                jQuery('#errorwarn_deliphone').hide();
2212            } else {
2213                jQuery('#errorwarn_deliphone').show();
2214                jQuery("#errorwarn_deliphone").html("Invalid phone number. Please use the format XXX-XXX-XXXX.");
2215            }
2216        }else{
2217            jQuery('#errorwarn_deliphone').hide();
2218        }
2219        
2220        //Maximum limit phone is 10 digit. Total:10
2221        if(numbers.length > maxCount){
2222            jQuery(this).val(jQuery(this).val().substring(0,maxCount));
2223        }
2224    }   
2225});
2226
2227//Payment billing address Zipcode and City auto fill input fields from API RetrieveCityStateForZipcode.
2228nc('#delipostalcode').on('blur',function(){
2229    var delipostalcode = jQuery('#delipostalcode').val();
2230    nc.ajax({
2231        type: "POST",
2232        url:""+nc('#admin_url').val()+"", 
2233        data:"action=custom_retrieve_city_state_zipcode&result=zipcode&zipcode="+delipostalcode, 
2234        beforeSend: function(){                 
2235             jQuery("#delicity").attr("placeholder", "Loading...");
2236             jQuery("#delistate").attr("placeholder", "Loading...");  
2237             jQuery('#errorwarn_postal_deli').hide();          
2238        },              
2239        success: function(msg){                      
2240                
2241            if(msg){  
2242
2243                //alert(msg);
2244                //console.log(msg);
2245
2246                var splitted = msg.split('==='); 
2247                var splitted_state_available = msg.split('###');      
2248
2249                //if(splitted[2] ){
2250                    nc('#delicity').empty();
2251                    nc('#delicity').val(splitted[2]); //city
2252                //}
2253
2254                //if(splitted[3] ){
2255                    nc('#delistate').empty();
2256                    nc('#delistate').val(splitted[3]); //state   
2257                //}   
2258
2259                if(splitted_state_available[1] =='Yes'){
2260                    //Check state available
2261                    nc('#delistate_available').empty();
2262                    nc('#delistate_available').val(splitted_state_available[1]);
2263
2264                    //jQuery("#delistate").removeClass("error");
2265                    jQuery('#errorwarn_postal_deli').hide();
2266
2267                }else if(splitted_state_available[1] =='No'){
2268                    //Check state available
2269                    nc('#delistate_available').empty();
2270                    nc('#delistate_available').val(splitted_state_available[1]);
2271
2272                    //jQuery("#delistate").addClass("error"); 
2273                    var state_name_available=""
2274                    if(splitted_state_available[2]!="")  {
2275
2276                        //state_name_available=splitted_state_available[2];
2277                        //jQuery('#errorwarn_postal_deli').show();
2278                        //jQuery("#errorwarn_postal_deli").html("We currently cannot ship items with alcohol to "+state_name_available+".");
2279                    }
2280                                 
2281                }else{
2282                    //Check state available
2283                    nc('#delistate_available').empty();
2284                    nc('#delistate_available').val(splitted_state_available[1]);
2285
2286                    jQuery("#avscity").attr("placeholder", "City");
2287                    jQuery("#avsstate").attr("placeholder", "State");   
2288
2289                    jQuery('#avserrorwarn_postal').show();
2290                    jQuery("#avserrorwarn_postal").html(msg);
2291                }
2292            }     
2293        }
2294    });
2295});
2296
2297//Get payment bill city 
2298nc('#delicity,#delistate').on('blur',function(){
2299    var delicity=jQuery('#delicity').val();
2300    var delipostalcode = jQuery('#delipostalcode').val();
2301    nc.ajax({
2302        type: "POST",
2303        url:""+nc('#admin_url').val()+"", 
2304        data:"action=custom_retrieve_city_state_zipcode&result=zipcode&zipcode="+delipostalcode+"&city="+delicity, 
2305        beforeSend: function(){
2306            //jQuery("#delicity").attr("placeholder", "Loading...");
2307            //jQuery("#delistate").attr("placeholder", "Loading...");  
2308            jQuery('#errorwarn_postal_deli').hide();   
2309        },              
2310        success: function(msg){              
2311
2312            if(msg){   
2313                //alert(msg);
2314
2315                //console.log(msg);
2316                var splitted = msg.split('==='); 
2317                var splitted_state_available = msg.split('###'); 
2318
2319                if(splitted[2] ){             
2320                  nc('#delicity').empty();
2321                  nc('#delicity').val(splitted[2]);
2322                }  
2323                if(splitted[3] ){
2324                  nc('#delistate').empty();
2325                  nc('#delistate').val(splitted[3]);     
2326                }   
2327
2328                if(splitted_state_available[1] =='Yes'){
2329
2330                    //Check state available
2331                    nc('#delistate_available').empty();
2332                    nc('#delistate_available').val(splitted_state_available[1]);
2333                       
2334                    //jQuery("#delistate").removeClass("error");
2335                    jQuery('#errorwarn_postal_deli').hide();
2336
2337                }else if(splitted_state_available[1] =='No'){
2338                    //Check state available
2339                    nc('#delistate_available').empty();
2340                    nc('#delistate_available').val(splitted_state_available[1]);
2341
2342                    //jQuery("#delistate").addClass("error"); 
2343                    var state_name_available=""
2344                    if(splitted_state_available[2]!="")  {
2345
2346                        //state_name_available=splitted_state_available[2];
2347                        //jQuery('#errorwarn_postal_deli').show();
2348                        //jQuery("#errorwarn_postal_deli").html("We currently cannot ship items with alcohol to "+state_name_available+".");
2349                    }
2350                                 
2351                }else{
2352                    //Check state available
2353                    nc('#delistate_available').empty();
2354                    nc('#delistate_available').val('');
2355 
2356                    jQuery('#errorwarn_postal_deli').show();
2357                    jQuery("#errorwarn_postal_deli").html(msg);
2358                }   
2359            }     
2360        }
2361    });
2362});
2363
2364//if giftcard or delivery note uncheck, empty input field.
2365nc("#isgift").change(function () {
2366    if (!nc(this).prop("checked")) {
2367        nc('#shipping #giftnotes').val('');
2368        nc('#shipping #emailaddress2').val('');
2369    }
2370});
2371
2372nc("#isdelivery").change(function () {
2373    if (!nc(this).prop("checked")) {
2374        nc('#shipping #notes').val('');
2375    }
2376});
2377
2378//if giftcard number uncheck, emtpy input field
2379nc("#redeem-gift-card").change(function () {
2380    if (!nc(this).prop("checked")) {
2381        nc('#gift-card-num').val('');
2382        nc('#security-code').val('');
2383        
2384        //call webgetcheckoutinfo api
2385        calling_getwebcheckoutinfo();
2386    }
2387});
2388//end
2389
2390//validate input number
2391nc(document).on('input', 'input[type="number"]', function () {
2392    let cleaned = nc(this).val().replace(/[^0-9]/g, '');
2393    nc(this).val(cleaned);
2394});
2395
2396}); //******End of main document******
2397
2398//Calling shipping service and shipping method.
2399function get_shipping_service_and_method_result(){
2400    var checkInterval = setInterval(function () {
2401        var shipstate = nc('#shipstate').val();
2402        //alert(shipstate);
2403        
2404        if (shipstate !== "") {
2405            clearInterval(checkInterval); // Stop checking
2406            
2407            nc.ajax({
2408                type: "POST",
2409                url:""+nc('#admin_url').val()+"", 
2410                data:"action=custom_retrieve_shipservi_shipmethd&result=shipservimethod&shipstate="+shipstate, 
2411                beforeSend: function(){                 
2412                     //jQuery("#shipcity").attr("placeholder", "Loading...");
2413                     //jQuery("#shipstate").attr("placeholder", "Loading...");  
2414                },              
2415                success: function(data){                      
2416                    if(data){  
2417                        //alert(data);
2418                        console.log(data);
2419                        jQuery('#errorwarn_postal_shservmethd').hide(); //Hide error warning.
2420                        var splitted = data.split('==='); 
2421                        
2422                        // Auto-select the shipping option
2423                        if(splitted[0]){
2424                            nc("#shipping-option").val(splitted[0]).change();
2425                        }
2426                        
2427                        // Auto-select the shipping method
2428                        if(splitted[1]){
2429                            nc("#shipping-method").val(splitted[1]).change();
2430                        }
2431                    }else{
2432                        jQuery('#errorwarn_postal_shservmethd').show();
2433                        jQuery("#errorwarn_postal_shservmethd").html("Please enter valid Zip Code / City.");
2434                    }    
2435                }
2436            });
2437        }else{
2438            jQuery('#errorwarn_postal_shservmethd').show();
2439            jQuery("#errorwarn_postal_shservmethd").html("Please enter valid Zip Code / City.");
2440        }
2441    }, 100); // Check every 100ms
2442}
2443
2444//Order History "view details" click slide open.
2445function openOrderHistory(id) {
2446    var nc = jQuery.noConflict();
2447    nc('.c7-history-'+id).css('right','0px');
2448}
2449
2450//close order history view details X click.
2451function closeHistory() {
2452    var nc = jQuery.noConflict();
2453    nc('.c7-cart.order').css('right','-510px');
2454}
2455
2456//Calling Web Get Checkout Info
2457function calling_getwebcheckoutinfo(){
2458    
2459    var islogin = nc('#hid_isloggedin').val(); //check is login.
2460    
2461    if (islogin && islogin === "1") {
2462        var customer_type = 'Login';
2463    }else{
2464        var customer_type = 'Guest';
2465    } 
2466    
2467    var delivery_type   = nc('#delivery-checkout .nav-item .nav-link.active').attr('data-delivery');
2468    var discountcode    = nc('#discount-code').val();
2469    var token           = nc("#hid_vaultid").val(); //token taken from hidden after updating
2470    var creditcardtype  = nc("#hid_creditcardtype").val(); //card type taken from hidden after adding creditcard.
2471    
2472    //Shipping
2473    var shipfirstname   = nc("#shipfirstname").val();
2474    var shiplastname    = nc("#shiplastname").val();
2475    var shipemail       = nc("#shipemail").val();
2476    var shipbirthdate   = nc("#shipbirthdate").val();
2477    var shipcompanyname = nc("#shipcompanyname").val();
2478    var shipaddress1    = nc("#shipaddress1").val();
2479    var shipaddress2    = nc("#shipaddress2").val();
2480    var shippostalcode  = nc("#shippostalcode").val();
2481    var shipcity        = nc("#shipcity").val();
2482    var shipstate       = nc("#shipstate").val();
2483    var shipphone       = nc("#shipphone").val();
2484    var shippingoption  = nc("#shipping-option").val(); //service
2485    var shippingmethod  = nc("#shipping-method").val(); //method
2486    var isgift          = nc("#isgift").prop("checked") ? nc("#isgift").val() : "";
2487    var giftnotes       = nc("#giftnotes").val();
2488    var emailaddress2   = nc("#emailaddress2").val();
2489    var notes           = nc("#notes").val();
2490
2491    //pickup 
2492    var pickupfirstname = nc("#pickupfirstname").val();
2493    var pickuplastname  = nc("#pickuplastname").val();
2494    var pickupemail     = nc("#pickupemail").val();  
2495    var birthdate       = nc("#birthdate").val();
2496    var checkout_pickuplocation = nc("#checkout_pickuplocation").val();
2497    
2498    //delivery
2499    var delifirstname   = nc("#delifirstname").val();
2500    var delilastname    = nc("#delilastname").val();
2501    var deliemail       = nc("#deliemail").val();
2502    var delicompanyname = nc("#delicompanyname").val();
2503    var deliaddress1    = nc("#deliaddress1").val();
2504    var deliaddress2    = nc("#deliaddress2").val();
2505    var delipostalcode  = nc("#delipostalcode").val();
2506    var delicity        = nc("#delicity").val();
2507    var delistate       = nc("#delistate").val();
2508    var deliphone       = nc("#deliphone").val();
2509    
2510    //PAYMENT/REVIEW
2511    var gift_card_num    = nc("#gift-card-num").val();
2512    var security_code    = nc("#security-code").val();
2513    var giftcard_id      = nc("#gifcrd_id").val();
2514    var giftcard_bal     = nc("#gifcrd_bal").val();
2515    var useloyaltypoints = nc("#redeem-loyal-point").prop("checked") ? nc("#redeem-loyal-point").val() : 0;
2516    
2517    var creditcardnum   = nc("#hid_creditcardnum").val();
2518    var expitationmonth = nc("#hid_expirationmonth").val();
2519    var expitationyear  = nc("#hid_expirationyear").val();
2520    //var creditcardcvv2  = nc("#creditcardcvv2").val();
2521    var avsaddress      = nc("#avsaddress").val();
2522    var avspostalcode   = nc("#avspostalcode").val();
2523    var avscity         = nc("#avscity").val();
2524    var avsstate        = nc("#avsstate").val();
2525    var allocation_id   = nc("#allocation_id").val();
2526    
2527    nc.ajax({
2528        type: "POST",
2529        url:""+nc('#admin_url').val()+"", 
2530        data: {
2531            action: "customize_calling_webgetcheckoutinfo",
2532            result: "call_webgetcheckout",
2533            delivery_type   : delivery_type,
2534            customer_type   : customer_type,
2535            discountcode    : discountcode,
2536            token           : token,
2537            creditcardtype  : creditcardtype,
2538            shipfirstname   : shipfirstname,
2539            shiplastname    : shiplastname,
2540            shipemail       : shipemail,
2541            shipbirthdate   : shipbirthdate,
2542            shipcompanyname : shipcompanyname,
2543            shipaddress1    : shipaddress1,
2544            shipaddress2    : shipaddress2,
2545            shippostalcode  : shippostalcode,
2546            shipcity        : shipcity,
2547            shipstate       : shipstate,
2548            shipphone       : shipphone,
2549            shippingoption  : shippingoption,
2550            shippingmethod  : shippingmethod,
2551            isgift          : isgift,
2552            giftnotes       : giftnotes, //no element
2553            emailaddress2   : emailaddress2,
2554            notes           : notes,
2555            pickupfirstname : pickupfirstname,
2556            pickuplastname  : pickuplastname,
2557            pickupemail     : pickupemail,
2558            birthdate       : birthdate,
2559            checkout_pickuplocation : checkout_pickuplocation,
2560            delifirstname   : delifirstname,
2561            delilastname    : delilastname,
2562            deliemail       : deliemail,
2563            delicompanyname : delicompanyname,
2564            deliaddress1    : deliaddress1,
2565            deliaddress2    : deliaddress2,
2566            delipostalcode  : delipostalcode,
2567            delicity        : delicity,
2568            delistate       : delistate,
2569            deliphone       : deliphone,
2570            gift_card_num   : gift_card_num,
2571            security_code   : security_code,
2572            giftcard_id     : giftcard_id,
2573            giftcard_bal    : giftcard_bal,
2574            useloyaltypoints: useloyaltypoints,
2575            creditcardnum   : creditcardnum,
2576            expitationmonth : expitationmonth,
2577            expitationyear  : expitationyear,
2578            //creditcardcvv2 : creditcardcvv2,
2579            avsaddress      : avsaddress,
2580            avspostalcode   : avspostalcode,
2581            avscity         : avscity,
2582            avsstate        : avsstate,
2583            allocation_id   : allocation_id,
2584        },
2585        beforeSend: function(){
2586            //alert('before send');
2587        },
2588        success: function(data){
2589            var splitted = data.split('===');
2590            if(data){
2591                console.log(data);
2592                
2593                //Convert from loading.. to calculate delivery fee text again.
2594                nc("#cal-deli-fee").empty().html('<i style="font-size: 14px;" class="fa fa-check me-2"></i>Calculate Delivery Fee');
2595                
2596                var subtotal = parseFloat(splitted[1]).toFixed(2);
2597                var discount = parseFloat(splitted[2]).toFixed(2);
2598                var deliveryfee = parseFloat(splitted[3]).toFixed(2);
2599                var tax = parseFloat(splitted[4]).toFixed(2);
2600                var total = parseFloat(splitted[5]).toFixed(2);
2601                var gift = parseFloat(splitted[6]).toFixed(2);
2602                var reward = parseFloat(splitted[7]).toFixed(2);
2603                
2604                nc(".sidebar_inventory_list").empty().html(splitted[0]);
2605                nc(".basket_subtotal").empty().html('$' + subtotal);
2606                nc(".basket_total").empty().html('$'+total);
2607                
2608                if (discount > 0) {
2609                    nc(".disc-con").removeClass('d-none').addClass('d-flex');
2610                    nc(".basket_discount").empty().html('$' + discount);
2611                } else {
2612                    nc(".disc-con").removeClass('d-flex').addClass('d-none');
2613                }
2614                
2615                if (deliveryfee > 0) {
2616                    nc(".deli-con").removeClass('d-none').addClass('d-flex');
2617                    nc(".basket_del_fee").empty().html('$' + deliveryfee);
2618                } else {
2619                    nc(".deli-con").removeClass('d-flex').addClass('d-none');
2620                }
2621                
2622                if (tax > 0) {
2623                    nc(".tax-con").removeClass('d-none').addClass('d-flex');
2624                    nc(".basket_tax").empty().html('$' + tax);
2625                } else {
2626                    nc(".tax-con").removeClass('d-flex').addClass('d-none');
2627                }
2628                
2629                //If GiftCardAmount is not empty
2630                if(gift > 0){
2631                    nc(".giftcard-con").removeClass('d-none').addClass('d-flex');
2632                    nc(".basket_gift").empty().html('$' + gift);
2633                }else{
2634                    nc(".giftcard-con").removeClass('d-flex').addClass('d-none');
2635                }
2636                
2637                //if reward is not empty
2638                if(reward > 0){
2639                    nc(".rewards-con").removeClass('d-none').addClass('d-flex');
2640                    nc(".basket_reward").empty().html('$' + reward);
2641                }else{
2642                    nc(".rewards-con").removeClass('d-flex').addClass('d-none');
2643                }
2644                
2645                //Hide/show not delivery message for Wisconsin
2646                if(splitted[8] > 0){
2647                    
2648                    nc(".amount-summary").show();
2649                    nc(".error_desc").hide('slow');
2650                    
2651                    if (discount > 0) {
2652                        nc(".disc-con").removeClass('d-none').addClass('d-flex');
2653                    } else {
2654                        nc(".disc-con").removeClass('d-flex').addClass('d-none');
2655                    }
2656                    
2657                    if (gift > 0) {
2658                        nc(".giftcard-con").removeClass('d-none').addClass('d-flex');
2659                    } else {
2660                        nc(".giftcard-con").removeClass('d-flex').addClass('d-none');
2661                    }
2662                    
2663                    if (reward > 0) {
2664                        nc(".rewards-con").removeClass('d-none').addClass('d-flex');
2665                    } else {
2666                        nc(".rewards-con").removeClass('d-flex').addClass('d-none');
2667                    }
2668                    
2669                    if (deliveryfee > 0) {
2670                        nc(".deli-con").removeClass('d-none').addClass('d-flex');
2671                    } else {
2672                        nc(".deli-con").removeClass('d-flex').addClass('d-none');
2673                    }
2674                    
2675                    if (tax > 0) {
2676                        nc(".tax-con").removeClass('d-none').addClass('d-flex');
2677                    } else {
2678                        nc(".tax-con").removeClass('d-flex').addClass('d-none');
2679                    }
2680                    
2681                }else{
2682                    nc(".amount-summary").hide('slow');
2683                    nc(".error_desc").show();
2684                }
2685                
2686            } 
2687        }
2688    });
2689}
2690
2691//Replace quantity restrict if greater then max
2692function stopreplaceqty(input, max) {
2693    const $input = nc(input); // Make sure you're using jQuery
2694    let value = parseInt($input.val(), 10);
2695
2696    if (value > max) {
2697        $input.val(max);
2698    }
2699}
2700
2701//Cart checkout page slider for (you might also like and Recent)
2702// slick slider
2703var pro_breakpoint = {
2704  // Small screen / phone
2705  sm: 576,   // Updated to match typical bootstrap sm breakpoint
2706  // Medium screen / tablet
2707  md: 768,
2708  // Large screen / desktop
2709  lg: 992,
2710  // Extra large screen / wide desktop
2711  xl: 1200
2712};
2713
2714var nc = jQuery.noConflict();
2715nc(window).on('load', function() { 
2716    var $sliders = nc('#checkout-slick-recent, #checkout-slick-like');
2717
2718    // Initialize Slick
2719    $sliders.slick({
2720        autoplay: false,
2721        autoplaySpeed: 1000,
2722        pauseOnFocus: false,
2723        draggable: true,
2724        infinite: true,
2725        dots: false,
2726        arrows: false,
2727        speed: 1000,
2728        mobileFirst: true,
2729        slidesToShow: 1,
2730        slidesToScroll: 1,
2731        responsive: [
2732            {
2733                breakpoint: pro_breakpoint.sm,
2734                settings: {
2735                    slidesToShow: 1,
2736                    slidesToScroll: 1,
2737                    arrows: true
2738                }
2739            },
2740            {
2741                breakpoint: pro_breakpoint.md,
2742                settings: {
2743                    slidesToShow: 3,
2744                    slidesToScroll: 1,
2745                    arrows: true
2746                }
2747            },
2748            {
2749                breakpoint: pro_breakpoint.lg,
2750                settings: {
2751                    slidesToShow: 4,
2752                    slidesToScroll: 1,
2753                    arrows: true
2754                }
2755            },
2756            {
2757                breakpoint: pro_breakpoint.xl,
2758                settings: {
2759                    slidesToShow: 4,
2760                    slidesToScroll: 1,
2761                    arrows: true
2762                }
2763            }
2764        ]
2765    });
2766
2767    //Fix width when switching tabs, Run this when a Bootstrap 5 tab becomes visible
2768    nc('a[data-bs-toggle="tab"]').on('shown.bs.tab', function (e) {
2769        const target = nc(e.target).attr("href");
2770
2771        if (target === '#cart-checkout' && $sliders.hasClass('slick-initialized')) {
2772            let tries = 0;
2773            let interval = setInterval(function() {
2774                const containerWidth = nc(target).width();
2775                if (containerWidth > 0 || tries > 10) {
2776                    clearInterval(interval);
2777                    $sliders.slick('refresh');
2778                }
2779                tries++;
2780            }, 100); // check every 100ms up to 1 second
2781        }
2782    });
2783});
2784//Slice scroll end.

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.