PageSourceSearch

https://www.lulacellars.com/wp-content/plugins/activ8-commerce/front/js/custom_cart_checkout.js

js lulacellars.com collected 2026-09-29 02:38:50 UTC 113,230 bytes, 2,781 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            if (response !== 'success') {
892                // Show CAPTCHA error
893                nc('#captcha_error').show();
894
895                // Refresh image
896                nc('#captcha-img').attr('src', myplugin_vars.plugin_url + 'includes/generate-captcha.php?rand=' + Date.now());
897
898                /*nc('html, body').animate({
899                    scrollTop: (nc('#captcha_error').offset().top - 300)
900                }, 700);*/
901
902                nc('.loader.small-loader_review').hide();
903                return false;
904            } else {
905                nc('#captcha_error').hide();
906    
907				//Review edits
908				//Display Customer Details in Review
909				var customername=nc('#shipfirstname').val()+' '+nc('#shiplastname').val();
910				var shipemail = nc('#shipemail').val();
911				var shipphone = nc('#shipphone').val();
912
913				//Shipping
914				var shiploc = nc('#shipcity').val()+', '+nc('#shipstate').val()+', '+nc('#shippostalcode').val();
915				nc("#display_shipaddress1").empty().html(nc('#shipaddress1').val());
916				nc("#display_shipaddress2").empty().html(nc('#shipaddress2').val());
917				nc("#display_shiploc").empty().html(shiploc);
918				
919				//Pickup
920				var avsloc = nc("#avscity").val()+', '+nc("#avsstate").val()+', '+nc("#avspostalcode").val();
921				var pickname=nc("#pickupfirstname").val()+' '+nc("#pickuplastname").val();
922				var pickemail = nc("#pickupemail").val(); 
923				nc("#display_pickuplocation").empty().html(nc("#checkout_pickuplocation").val());
924				nc("#display_avsaddress").empty().html(nc("#avsaddress").val());
925				nc("#display_avsloc").empty().html(avsloc);
926				
927				//Delivery
928				var deliname = nc("#delifirstname").val()+' '+nc("#delilastname").val();
929				var dloc = nc("#delicity").val()+', '+nc("#delistate").val()+', '+nc("#delipostalcode").val();
930				var deliemail = nc("#deliemail").val();
931				var deliphone = nc("#deliphone").val();
932				nc("#display_deliaddress1").empty().html(nc("#deliaddress1").val());
933				nc("#display_deliaddress2").empty().html(nc("#deliaddress2").val());
934				nc("#display_deliloc").empty().html(dloc);
935				
936				
937				// Choose which name to display
938				if (pickname && pickname.trim() !== '') {
939					nc("#display_custname_chk").empty().text(pickname);
940				} else if (deliname && deliname.trim() !== '') {
941					nc("#display_custname_chk").empty().text(deliname);
942				} else {
943					nc("#display_custname_chk").empty().text(customername);
944				}
945				
946				//Choose email
947				if (shipemail && shipemail.trim() !== '') {
948					nc("#display_shipemail_chk").empty().text(shipemail);
949				} else if (pickemail && pickemail.trim() !== '') {
950					nc("#display_shipemail_chk").empty().text(pickemail);
951				} else {
952					nc("#display_shipemail_chk").empty().text(deliemail);
953				}
954				
955				//choose phone
956				if (shipphone && shipphone.trim() !== '') {
957					nc("#display_shipphone_chk").empty().text(shipphone);
958				} else {
959					nc("#display_shipphone_chk").empty().text(deliphone);
960				}
961				
962				//Message
963				var giftnote = nc('#giftnotes').val();
964				var giftmail = nc('#shipping #emailaddress2').val();
965				var note = nc('#notes').val();
966				
967				if(!giftnote && !note){
968					nc(".hide_msgsec").hide();
969				}else{
970					nc(".hide_msgsec").show();
971				}
972				
973				if(giftnote){
974					nc("#gift_msg_title").show();
975					nc("#display_gift_msg").empty().html(giftnote);
976				}else{
977					nc("#gift_msg_title").hide();
978					nc("#display_gift_msg").empty();
979				}
980				
981				if(note){
982					nc("#deli_msg_title").show();
983					nc("#display_deli_msg").empty().html(note);
984				}else{
985					nc("#deli_msg_title").hide();
986					nc("#display_deli_msg").empty();
987				}
988				//review ends.
989				
990				//Display Payment Details in Review
991				var customerid = nc('#hid_customerid').val();
992				var creditcardnum = nc('#creditcardnum').val();
993				var creditcardtype = nc('#hid_creditcardtype').val();
994				if(creditcardtype && creditcardtype.trim() !== ''){
995					creditcardtype = creditcardtype;
996				}else{
997					creditcardtype = '';
998				}
999				var creditcardnum_last4 = '**** **** '+creditcardnum.substr(creditcardnum.length - 4);
1000				nc("#display_creditcardnum").html(creditcardtype +' '+creditcardnum_last4);
1001				var expirationmonth = nc('#expirationmonth').val();
1002				var expirationyear = nc('#expirationyear').val();
1003				nc("#display_creditcardexpiry").html('Expiration: '+expirationmonth+'/'+expirationyear);
1004				
1005				let update_card = nc("#update_card").prop("checked") ? nc('#update_card').val() : ''; //Yes
1006				
1007				var errors = 0;
1008				// Validation empty field where data-required = "yes".
1009				nc('#payreview-checkout.active .credit-cards input[data-required="yes"]').each(function() {
1010					if (!nc(this).val().trim()) {
1011						nc(this).addClass('error');
1012						nc('html, body').animate({
1013							 scrollTop: (nc('.error').offset().top - 400)
1014						}, 700);
1015						errors++;
1016					} else {
1017						nc(this).removeClass('error');
1018					}
1019				});
1020				
1021				// If there are empty fields, stop execution
1022				if (errors > 0) {
1023					nc('#rev_errorwarn').show();
1024					nc('#rev_errorwarn').empty().html("Please fill the required fields.");
1025					return false;
1026				}else{
1027					nc('#rev_errorwarn').hide();
1028				}
1029				
1030				//Check if the credictcard field is not with XXXXXXXXXXXX.
1031				if (creditcardnum && !String(creditcardnum).startsWith('XXXXXXXXXXXX')) {
1032					
1033					//Credit Card Validation
1034					var errors_credit=0;
1035					//var cardNumber = nc("#creditcardnum").val();
1036					var cvv = nc("#creditcardcvv2").val();
1037					var encCardNum = nc("#encrypt_creditcardnum").val();
1038				
1039					jQuery.ajax({
1040						type: "POST",
1041						url:""+nc('#admin_url').val()+"", 
1042						data: {
1043							action: "custom_validate_creditcard_payment",
1044							result: "validate_cardpayment",
1045							card_num: encCardNum,
1046							expirationmonth: expirationmonth,
1047							expirationyear: expirationyear,
1048							cvv:cvv,
1049							customerid: customerid,
1050							update_card: update_card,
1051						},
1052						beforeSend: function(){
1053							nc('.loader.small-loader_review').show();
1054						},              
1055						success: function(msg){
1056							if(msg){
1057								var splitted = msg.split('===');
1058								console.log(msg);
1059								//alert(msg);
1060								
1061								if(splitted[0] > 0){
1062									//after validate code will come here.
1063									var creditcardnum = splitted[2];
1064									var vaultid = splitted[3];
1065									var expirationmonth = splitted[4];
1066									var expirationyear = splitted[5];
1067									var creditcardtype = splitted[6];
1068									var cardnum_last4 = '**** **** '+creditcardnum.substr(creditcardnum.length - 4);
1069									
1070									nc("#errorwarn_creditcard").hide(); //hide credit card error warning.
1071									nc("#hid_creditcardnum,#creditcardnum").val(creditcardnum);
1072									nc("#hid_vaultid").val(vaultid);
1073									nc("#hid_expirationmonth").val(expirationmonth);
1074									nc("#hid_expirationyear").val(expirationyear);
1075									nc('#hid_creditcardtype').val(creditcardtype);
1076									nc("#display_creditcardnum").html(creditcardtype +' '+cardnum_last4);
1077									
1078									//Calling function webgetcheckoutinfo API
1079									calling_getwebcheckoutinfo(); 
1080						
1081									// Proceed to checkout
1082									nc('.loader.small-loader_review').hide(); //hide loader.
1083									nc('#pay-checkout-sec').hide();
1084									nc('#review-checkout-sec').show();
1085					
1086								}else if(splitted[0] === ''){ //if basket due total is 0.00 and gift card balance not 0.00, remove credit card validation 
1087									
1088									//Calling function webgetcheckoutinfo API
1089									calling_getwebcheckoutinfo(); 
1090						
1091									// Proceed to checkout
1092									nc('.loader.small-loader_review').hide(); //hide loader.
1093									nc('#pay-checkout-sec').hide();
1094									nc('#review-checkout-sec').show();
1095									
1096								}else{
1097									errors_credit=1;
1098									nc('#errorwarn_creditcard').show();
1099									nc("#errorwarn_creditcard").empty().html(splitted[1]);
1100									nc('.loader.small-loader_review').hide(); //hide loader.
1101									nc('html, body').animate({
1102										 scrollTop: (nc('#errorwarn_creditcard').offset().top - 300)
1103									}, 700); //scroll top to creditcard tab.
1104									return false;
1105								}
1106								nc('html, body').animate({
1107									 scrollTop: (nc('#errorwarn_creditcard').offset().top - 300)
1108								}, 700); //scroll top to creditcard tab.
1109							} 
1110						}
1111					});
1112					
1113				}else{
1114					// Proceed to checkout
1115					nc('#pay-checkout-sec').hide();
1116					nc('#review-checkout-sec').show();
1117				}
1118	        } // End of else (captcha passed)
1119        } // End success
1120    }); // End AJAX
1121});
1122
1123//Sbumit final button Complete Order.
1124nc(document).on('submit', '#review-checkout-sec', function(event){
1125    event.preventDefault(); // Prevent page reload
1126    
1127    var iagreechk = nc("#iagree_chk").val();
1128    var islogin   = nc('#hid_isloggedin').val(); //check is login.
1129    var deliveryType = nc("#delivery-checkout .nav .nav-link.active").attr("data-delivery");
1130    
1131    var username = nc('#user-name').val();
1132    var userpass = nc('#encryptcreatepassword').val();
1133    var cus_type = nc('#cus_type').val();
1134    
1135    //If pickup is enabled, checkbox not showing
1136    if(deliveryType !== 'Pickup'){
1137        // Check if the "I agree" checkbox is checked
1138        if (iagreechk === 'Yes' && !nc("#iagree").prop("checked")) {
1139            alert("You must agree to the Shipping Terms and Conditions before proceeding.");
1140            return false; // Stop form submission
1141        }
1142    }
1143    
1144    //Check customer type
1145    if(cus_type && cus_type === 'Register'){
1146        var customer_type = 'Register';
1147    }else{
1148        if (islogin && islogin === "1") {
1149            var customer_type = 'Login';
1150        }else{
1151            var customer_type = 'Guest';
1152        }
1153    }
1154    
1155    var delivery_type   = nc('#delivery-checkout .nav-item .nav-link.active').attr('data-delivery');
1156    var discountcode    = nc('#discount-code').val();
1157    var token           = nc("#hid_vaultid").val(); //token taken from hidden after adding creditcard.
1158    var creditcardtype  = nc("#hid_creditcardtype").val(); //card type taken from hidden after adding creditcard.
1159    
1160    //Shipping
1161    var shipfirstname   = nc("#shipfirstname").val();
1162    var shiplastname    = nc("#shiplastname").val();
1163    var shipemail       = nc("#shipemail").val();
1164    var shipbirthdate   = nc("#shipbirthdate").val();
1165    var shipcompanyname = nc("#shipcompanyname").val();
1166    var shipaddress1    = nc("#shipaddress1").val();
1167    var shipaddress2    = nc("#shipaddress2").val();
1168    var shippostalcode  = nc("#shippostalcode").val();
1169    var shipcity        = nc("#shipcity").val();
1170    var shipstate       = nc("#shipstate").val();
1171    var shipphone       = nc("#shipphone").val();
1172    var shippingoption  = nc("#shipping-option").val(); //service
1173    var shippingmethod  = nc("#shipping-method").val(); //method
1174    var isgift          = nc("#isgift").prop("checked") ? nc("#isgift").val() : "";
1175    var giftnotes       = nc("#giftnotes").val();
1176    var emailaddress2   = nc("#emailaddress2").val();
1177    var notes           = nc("#notes").val();
1178
1179    //pickup 
1180    var pickupfirstname = nc("#pickupfirstname").val();
1181    var pickuplastname  = nc("#pickuplastname").val();
1182    var pickupemail     = nc("#pickupemail").val();
1183    var birthdate       = nc("#birthdate").val();
1184    var checkout_pickuplocation = nc("#checkout_pickuplocation").val();
1185    
1186    //delivery
1187    var delifirstname   = nc("#delifirstname").val();
1188    var delilastname    = nc("#delilastname").val();
1189    var deliemail       = nc("#deliemail").val();
1190    var delicompanyname = nc("#delicompanyname").val();
1191    var deliaddress1    = nc("#deliaddress1").val();
1192    var deliaddress2    = nc("#deliaddress2").val();
1193    var delipostalcode  = nc("#delipostalcode").val();
1194    var delicity        = nc("#delicity").val();
1195    var delistate       = nc("#delistate").val();
1196    var deliphone       = nc("#deliphone").val();
1197    
1198    //PAYMENT/REVIEW
1199    var gift_card_num    = nc("#gift-card-num").val();
1200    var security_code    = nc("#security-code").val();
1201    var giftcard_id      = nc("#gifcrd_id").val();
1202    var giftcard_bal     = nc("#gifcrd_bal").val();
1203    var useloyaltypoints = nc("#redeem-loyal-point").prop("checked") ? nc("#redeem-loyal-point").val() : 0;
1204    
1205    var creditcardnum   = nc("#hid_creditcardnum").val();
1206    var expitationmonth = nc("#hid_expirationmonth").val();
1207    var expitationyear  = nc("#hid_expirationyear").val();
1208    //var creditcardcvv2  = nc("#creditcardcvv2").val();
1209    var avsaddress      = nc("#avsaddress").val();
1210    var avspostalcode   = nc("#avspostalcode").val();
1211    var avscity         = nc("#avscity").val();
1212    var avsstate        = nc("#avsstate").val();
1213    var allocation_id   = nc("#allocation_id").val();
1214    
1215    jQuery.ajax({
1216        type: "POST",
1217        url:""+jQuery('#admin_url').val()+"", 
1218        data: {
1219            action: "custom_complete_order",
1220            result: "complete_order",
1221            delivery_type   : delivery_type,
1222            customer_type   : customer_type,
1223            discountcode    : discountcode,
1224            token           : token,
1225            creditcardtype  : creditcardtype,
1226            shipfirstname   : shipfirstname,
1227            shiplastname    : shiplastname,
1228            shipemail       : shipemail,
1229            shipbirthdate   : shipbirthdate,
1230            shipcompanyname : shipcompanyname,
1231            shipaddress1    : shipaddress1,
1232            shipaddress2    : shipaddress2,
1233            shippostalcode  : shippostalcode,
1234            shipcity        : shipcity,
1235            shipstate       : shipstate,
1236            shipphone       : shipphone,
1237            shippingoption  : shippingoption,
1238            shippingmethod  : shippingmethod,
1239            isgift          : isgift,
1240            giftnotes       : giftnotes, //no element
1241            emailaddress2   : emailaddress2,
1242            notes           : notes,
1243            pickupfirstname : pickupfirstname,
1244            pickuplastname  : pickuplastname,
1245            pickupemail     : pickupemail,
1246            birthdate       : birthdate,
1247            checkout_pickuplocation : checkout_pickuplocation,
1248            delifirstname   : delifirstname,
1249            delilastname    : delilastname,
1250            deliemail       : deliemail,
1251            delicompanyname : delicompanyname,
1252            deliaddress1    : deliaddress1,
1253            deliaddress2    : deliaddress2,
1254            delipostalcode  : delipostalcode,
1255            delicity        : delicity,
1256            delistate       : delistate,
1257            deliphone       : deliphone,
1258            gift_card_num   : gift_card_num,
1259            security_code   : security_code,
1260            giftcard_id     : giftcard_id,
1261            giftcard_bal    : giftcard_bal,
1262            useloyaltypoints: useloyaltypoints,
1263            creditcardnum   : creditcardnum,
1264            expitationmonth : expitationmonth,
1265            expitationyear  : expitationyear,
1266            //creditcardcvv2 : creditcardcvv2,
1267            avsaddress      : avsaddress,
1268            avspostalcode   : avspostalcode,
1269            avscity         : avscity,
1270            avsstate        : avsstate,
1271            allocation_id   : allocation_id,
1272            username        : username,
1273            userpass        : userpass,
1274        },
1275        beforeSend: function(){
1276            nc('.loader.small-loader_completeorder').show();
1277        },              
1278        success: function(msg){
1279            if(msg){
1280                var splitted = msg.split('===');
1281                console.log(msg);
1282                
1283                nc('.loader.small-loader_completeorder').hide();
1284                
1285                if(splitted[0] > 0){
1286                    //nc('#review-checkout-sec').hide();
1287                    //nc('#thank-you-message').show();
1288                    //nc('#thank-you-message').empty().html(splitted[1]);
1289                    //nc('.nav.main').hide();
1290                    // redirect to new thank you page..... after success...
1291                    window.location.href = window.location.origin + "/acs-thank-you";
1292                }else{
1293                    nc('#thank-you-message').hide();
1294                    nc('#completeorder-final-result').empty().html(splitted[1]);
1295                }
1296            } 
1297        }
1298    });
1299});
1300
1301//calculate delivery fee button click
1302nc(document).on('click', '#cal-deli-fee', function(){
1303
1304    var errors = 0;
1305    // Validation empty field where data-required = "yes".
1306    jQuery('#delivery-checkout .tab-pane.active input[data-required="yes"]').each(function() {
1307        if (!jQuery(this).val().trim()) {
1308            jQuery(this).addClass('error');
1309            jQuery('html, body').animate({
1310                 scrollTop: (jQuery('.error').offset().top - 300)
1311            }, 700);
1312            errors++;
1313        } else {
1314            jQuery(this).removeClass('error');
1315        }
1316    });
1317	
1318	//Empty field validation. 
1319    if(errors > 0){      
1320        if(errors > 0){           
1321            jQuery('.errorwarn_delivery').show();
1322            jQuery('.errorwarn_delivery').html("Please fill the required fields.");
1323        } 
1324        return false; 
1325    }else{
1326	    nc("#cal-deli-fee").empty().html('<i style="font-size: 16px;" class="fa fa-circle-thin me-2"></i>Loading...');
1327        
1328        //Calling function webgetcheckoutinfo API
1329        calling_getwebcheckoutinfo();  
1330	}
1331});
1332//End
1333
1334//Call getwebcheckoutinfo on each delivery tabs clicks(ship,pickup,delivery)
1335/*nc('.nav-link').on('click', function() {
1336    if ((nc(this).attr('href') === '#shipping' && nc(this).hasClass('active'))){
1337        //alert('dddd');
1338        //calling_getwebcheckoutinfo();
1339    }
1340});*/
1341
1342//edit-cart
1343nc('.edit-cart').on('click', function(e){
1344    e.preventDefault();
1345    var tab_val = nc(this).attr("data-id");
1346	
1347	//activate next tab
1348	var next_tab = nc('.nav a.active').parent('li').next('li').find('a');
1349	if(next_tab.length > 0){
1350	  nc('.nav a[href="#'+ tab_val +'"]').tab('show');
1351	}
1352});
1353
1354//Edit Customer
1355nc('#chkout_customer_btn').on('click', function(){       
1356    jQuery('.nav a[href="#delivery-checkout"]').tab('show');        
1357});
1358
1359//Edit Shipping.
1360nc('#chkout_shipping_btn').on('click', function(){        
1361    jQuery('.nav a[href="#delivery-checkout"]').tab('show');        
1362});
1363
1364//Edit Pickup.
1365nc('#chkout_pickup_btn').on('click', function(){        
1366    jQuery('.nav a[href="#delivery-checkout"]').tab('show');        
1367});
1368
1369//Edit Delivery.
1370nc('#chkout_delivery_btn').on('click', function(){        
1371    jQuery('.nav a[href="#delivery-checkout"]').tab('show');        
1372});
1373
1374//Edit Message.
1375nc('#chkout_message_btn').on('click', function(){        
1376    jQuery('.nav a[href="#delivery-checkout"]').tab('show');        
1377});
1378
1379//Edit Payment
1380nc('#chkout_payment_btn').on('click', function(){        
1381    jQuery('.nav a[href="#payreview-checkout"]').tab('show');
1382    jQuery('#review-checkout-sec').hide();
1383    jQuery('#pay-checkout-sec').show();
1384});
1385
1386//Auto copy Customer names to ship name and pickup name.
1387nc('#first-name,#shipfirstname').on('keyup', function(){
1388    var cfn = jQuery(this).val();
1389    jQuery('#shipfirstname,#pickupfirstname,#delifirstname').empty().val(cfn);
1390});
1391
1392nc('#last-name,#shiplastname').on('keyup', function(){
1393    var cln = jQuery(this).val();
1394    jQuery('#shiplastname,#pickuplastname,#delilastname').empty().val(cln);
1395});
1396
1397//Auto copy email address ship to delivery
1398nc('#shipemail').on('keyup', function(){
1399    var cem = jQuery(this).val();
1400    jQuery('#deliemail,#pickupemail').empty().val(cem);
1401});
1402
1403//update email delviery section email field if user type email address on username
1404nc('#user-name').on('keyup', function () {
1405    var usname = nc(this).val();
1406    var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
1407
1408    if (emailPattern.test(usname)) {
1409        nc('#shipemail, #deliemail, #pickupemail').val(usname);
1410    }
1411});
1412
1413//Get Selected Pickup Location
1414nc('#checkout_pickuplocation').change(function() {
1415    var pickuplocation_name=jQuery('#checkout_pickuplocation').find(":selected").val();
1416    var pickuplocation_address=jQuery('#checkout_pickuplocation').find(":selected").data('address');
1417    var pickuplocation_city=jQuery('#checkout_pickuplocation').find(":selected").data('city');
1418    var pickuplocation_state=jQuery('#checkout_pickuplocation').find(":selected").data('state');
1419    var pickuplocation_zipcode=jQuery('#checkout_pickuplocation').find(":selected").data('zipcode');
1420    var pickuplocation_phone=jQuery('#checkout_pickuplocation').find(":selected").data('phone');
1421
1422    // Change content    
1423    nc("#display_checkout_pickuplocation #pickuplocation_name").text(pickuplocation_name);
1424    nc("#display_checkout_pickuplocation #pickup_location_address").text(pickuplocation_address+' '+pickuplocation_city+' '+pickuplocation_state+' '+pickuplocation_zipcode);
1425    nc("#display_checkout_pickuplocation #pickuplocation_phone").text(pickuplocation_phone);
1426    nc("#display_checkout_pickuplocation").show(); 
1427});
1428
1429//Hide/show gift-card-sec
1430nc('#redeem-gift-card').on('click', function(){
1431    if(jQuery("#redeem-gift-card").is(':checked')){
1432        jQuery("#gift-card-sec").show();
1433    } else {
1434        jQuery("#gift-card-sec").hide();
1435    }        
1436});
1437
1438//hide/show loyal-point-sec
1439nc('#redeem-loyal-point').on('click', function(){
1440    if(jQuery("#redeem-loyal-point").is(':checked')){
1441        jQuery("#loyal-point-sec").show();
1442    } else {
1443        jQuery("#loyal-point-sec").hide();
1444    }        
1445});
1446
1447//Check if the security code is not null.
1448nc('#security-code').on('keyup', function() {
1449    if (nc(this).val().trim() === '') {
1450        nc('#gift-card-redeem-btn').html('<i class="fa fa-check me-2"></i> Check Balance');
1451    }
1452});
1453
1454//Review / Redeem Gift Card
1455nc(document).on('click', '.redeem-btn', function(){
1456    event.preventDefault();
1457    
1458    var gift_card_num  = nc("#gift-card-num").val();
1459    var security_code  = nc("#security-code").val();
1460
1461    //validation empty field 
1462    var errors = 0;
1463    nc('#gift-card-sec :input[data-required = "yes"]').map(function(){
1464        if( !nc(this).val().trim()) {
1465            nc(this).addClass('error');
1466            errors++;
1467        } else if (nc(this).val()) {
1468            nc(this).removeClass('error');
1469        }   
1470    });
1471
1472    //Empty field validation.
1473    if(errors > 0){
1474        //nc('#errorwarn_gif').show();
1475        //nc('#errorwarn_gif').html("Please fill the required fields.");
1476        return false;
1477        
1478    }else{
1479        //nc('#errorwarn_gif').hide('slow'); //hide error warning.
1480        nc.ajax({
1481            type: "POST",
1482            url:""+nc('#admin_url').val()+"", 
1483           data: {
1484                action: "customize_redeem_gift_card",
1485                result: "redeem_giftcard",
1486                gift_card_num : gift_card_num,
1487                security_code : security_code,
1488            },
1489            beforeSend: function(){
1490                nc('#gift-card-redeem-btn').html('<i style="font-size: 16px;" class="fa fa-circle-thin me-2"></i>Loading...');
1491            },
1492            success: function(data){
1493                var splitted = data.split('===');
1494                if(data){
1495                    console.log(data);
1496                    if(splitted[1] > 0){
1497                        var bal = parseFloat(splitted[1]).toFixed(2);
1498                        nc('#gift-card-redeem-btn').empty().html('<i class="fa fa-check me-2"></i> Redeem').removeClass('redeem-btn').addClass('redeem-now');
1499                        nc('.giftcard-result').show().empty().html('The Gift Card has a balance of <b>$'+bal+'</b> that can be applied to this order.');
1500                        nc('#gifcrd_id').val(splitted[2]);
1501                        nc('#gifcrd_bal').val(bal);
1502                    }else{
1503                        nc('#gift-card-redeem-btn').empty().html('<i class="fa fa-check me-2"></i> Check Balance');
1504                        nc('.giftcard-result').show().empty().html('<span id="errorwarn">'+splitted[0]+'</span>');
1505                    }
1506                } 
1507            }
1508        });
1509    }       
1510});
1511
1512//Redeem now
1513nc(document).on('click', '.redeem-now', function(){
1514    event.preventDefault();
1515    var gift_card_chk  = nc("#redeem-gift-card").prop("checked") ? nc("#redeem-gift-card").val() : ""; //Yes
1516    var reward_chk     = nc("#redeem-loyal-point").prop("checked") ? nc("#redeem-loyal-point").val() : 0;
1517    
1518    var islogin        = nc('#hid_isloggedin').val(); //check is login.
1519    
1520    if (islogin && islogin === "1") {
1521        var customer_type = 'Login';
1522    }else{
1523        var customer_type = 'Guest';
1524    }
1525    
1526    var delivery_type   = nc('#delivery-checkout .nav-item .nav-link.active').attr('data-delivery');
1527    var discountcode    = nc('#discount-code').val();
1528    var token           = nc("#hid_vaultid").val(); //token taken from hidden after updating
1529    var creditcardtype  = nc("#hid_creditcardtype").val(); //card type taken from hidden after adding creditcard.
1530    
1531    //Shipping
1532    var shipfirstname   = nc("#shipfirstname").val();
1533    var shiplastname    = nc("#shiplastname").val();
1534    var shipemail       = nc("#shipemail").val();
1535    var shipbirthdate   = nc("#shipbirthdate").val();
1536    var shipcompanyname = nc("#shipcompanyname").val();
1537    var shipaddress1    = nc("#shipaddress1").val();
1538    var shipaddress2    = nc("#shipaddress2").val();
1539    var shippostalcode  = nc("#shippostalcode").val();
1540    var shipcity        = nc("#shipcity").val();
1541    var shipstate       = nc("#shipstate").val();
1542    var shipphone       = nc("#shipphone").val();
1543    var shippingoption  = nc("#shipping-option").val(); //service
1544    var shippingmethod  = nc("#shipping-method").val(); //method
1545    var isgift          = nc("#isgift").prop("checked") ? nc("#isgift").val() : "";
1546    var giftnotes       = nc("#giftnotes").val();
1547    var emailaddress2   = nc("#emailaddress2").val();
1548    var notes           = nc("#notes").val();
1549
1550    //pickup 
1551    var pickupfirstname = nc("#pickupfirstname").val();
1552    var pickuplastname  = nc("#pickuplastname").val();
1553    var pickupemail     = nc("#pickupemail").val();  
1554    var birthdate       = nc("#birthdate").val();
1555    var checkout_pickuplocation = nc("#checkout_pickuplocation").val();
1556    
1557    //delivery
1558    var delifirstname   = nc("#delifirstname").val();
1559    var delilastname    = nc("#delilastname").val();
1560    var deliemail       = nc("#deliemail").val();
1561    var delicompanyname = nc("#delicompanyname").val();
1562    var deliaddress1    = nc("#deliaddress1").val();
1563    var deliaddress2    = nc("#deliaddress2").val();
1564    var delipostalcode  = nc("#delipostalcode").val();
1565    var delicity        = nc("#delicity").val();
1566    var delistate       = nc("#delistate").val();
1567    var deliphone       = nc("#deliphone").val();
1568    
1569    //PAYMENT/REVIEW
1570    var gift_card_num    = nc("#gift-card-num").val();
1571    var security_code    = nc("#security-code").val();
1572    var giftcard_id      = nc("#gifcrd_id").val();
1573    var giftcard_bal     = nc("#gifcrd_bal").val();
1574    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.
1575    
1576    var creditcardnum   = nc("#hid_creditcardnum").val();
1577    var expitationmonth = nc("#hid_expirationmonth").val();
1578    var expitationyear  = nc("#hid_expirationyear").val();
1579    //var creditcardcvv2  = nc("#creditcardcvv2").val();
1580    var avsaddress      = nc("#avsaddress").val();
1581    var avspostalcode   = nc("#avspostalcode").val();
1582    var avscity         = nc("#avscity").val();
1583    var avsstate        = nc("#avsstate").val();
1584    var allocation_id   = nc("#allocation_id").val();
1585    
1586    //validation empty field 
1587    var errors = 0;
1588    nc('#gift-card-sec :input[data-required = "yes"]').map(function(){
1589        if(!nc(this).val().trim()) {
1590            nc(this).addClass('error');
1591            errors++;
1592        } else if (nc(this).val()) {
1593            nc(this).removeClass('error');
1594        }   
1595    });
1596
1597    //Empty field validation.
1598    if(errors > 0){
1599        return false;
1600    }else{
1601        nc.ajax({
1602            type: "POST",
1603            url:""+nc('#admin_url').val()+"", 
1604           data: {
1605                action: "customize_redeem_now",
1606                result: "gift_redeem_now",
1607                useloyaltypoints: useloyaltypoints,
1608                giftcard_id     : giftcard_id, //important
1609                giftcard_bal    : giftcard_bal, //important
1610                gift_card_chk   : gift_card_chk, //important
1611                reward_chk      : reward_chk, //important
1612                delivery_type   : delivery_type,
1613                customer_type   : customer_type,
1614                discountcode    : discountcode,
1615                token           : token,
1616                creditcardtype  : creditcardtype,
1617                shipfirstname   : shipfirstname,
1618                shiplastname    : shiplastname,
1619                shipemail       : shipemail,
1620                shipbirthdate   : shipbirthdate,
1621                shipcompanyname : shipcompanyname,
1622                shipaddress1    : shipaddress1,
1623                shipaddress2    : shipaddress2,
1624                shippostalcode  : shippostalcode,
1625                shipcity        : shipcity,
1626                shipstate       : shipstate,
1627                shipphone       : shipphone,
1628                shippingoption  : shippingoption,
1629                shippingmethod  : shippingmethod,
1630                isgift          : isgift,
1631                giftnotes       : giftnotes, //no element
1632                emailaddress2   : emailaddress2,
1633                notes           : notes,
1634                pickupfirstname : pickupfirstname,
1635                pickuplastname  : pickuplastname,
1636                pickupemail     : pickupemail,
1637                birthdate       : birthdate,
1638                checkout_pickuplocation : checkout_pickuplocation,
1639                delifirstname   : delifirstname,
1640                delilastname    : delilastname,
1641                deliemail       : deliemail,
1642                delicompanyname : delicompanyname,
1643                deliaddress1    : deliaddress1,
1644                deliaddress2    : deliaddress2,
1645                delipostalcode  : delipostalcode,
1646                delicity        : delicity,
1647                delistate       : delistate,
1648                deliphone       : deliphone,
1649                gift_card_num   : gift_card_num,
1650                security_code   : security_code,
1651                creditcardnum   : creditcardnum,
1652                expitationmonth : expitationmonth,
1653                expitationyear  : expitationyear,
1654                //creditcardcvv2 : creditcardcvv2,
1655                avsaddress      : avsaddress,
1656                avspostalcode   : avspostalcode,
1657                avscity         : avscity,
1658                avsstate        : avsstate,
1659                allocation_id   : allocation_id,
1660            },
1661            beforeSend: function(){
1662                nc('#gift-card-redeem-btn').html('<i style="font-size: 16px;" class="fa fa-circle-thin me-2"></i>Loading...');
1663            },
1664            success: function(data){
1665                var splitted = data.split('===');
1666                console.log(splitted); 
1667                
1668                var subtotal = parseFloat(splitted[1]).toFixed(2);
1669                var discount = parseFloat(splitted[2]).toFixed(2);
1670                var deliveryfee = parseFloat(splitted[3]).toFixed(2);
1671                var tax = parseFloat(splitted[4]).toFixed(2);
1672                var total = parseFloat(splitted[5]).toFixed(2);
1673                var gift = parseFloat(splitted[6]).toFixed(2);
1674                var reward = parseFloat(splitted[7]).toFixed(2);
1675                
1676                nc(".sidebar_inventory_list").empty().html(splitted[0]);
1677                nc(".basket_subtotal").empty().html('$' + subtotal);
1678                nc(".basket_total").empty().html('$'+total);
1679                
1680                if (discount > 0) {
1681                    nc(".disc-con").removeClass('d-none').addClass('d-flex');
1682                    nc(".basket_discount").empty().html('$' + discount);
1683                } else {
1684                    nc(".disc-con").removeClass('d-flex').addClass('d-none');
1685                }
1686                
1687                if (deliveryfee > 0) {
1688                    nc(".deli-con").removeClass('d-none').addClass('d-flex');
1689                    nc(".basket_del_fee").empty().html('$' + deliveryfee);
1690                } else {
1691                    nc(".deli-con").removeClass('d-flex').addClass('d-none');
1692                }
1693                
1694                if (tax > 0) {
1695                    nc(".tax-con").removeClass('d-none').addClass('d-flex');
1696                    nc(".basket_tax").empty().html('$' + tax);
1697                } else {
1698                    nc(".tax-con").removeClass('d-flex').addClass('d-none');
1699                }
1700                
1701                //If GiftCardAmount is not empty
1702                if(gift > 0){
1703                    nc(".giftcard-con").removeClass('d-none').addClass('d-flex');
1704                    nc(".basket_gift").empty().html('$' + gift);
1705                    
1706                    nc('#gift-card-redeem-btn').empty().html('<i class="fa fa-check me-2"></i> Redeemed').removeClass('redeem-now').addClass('redeem-btn');
1707                    nc(".giftcard-result").empty().html('<b>$'+gift+'</b> has been applied to this order.');
1708                    nc('#is-gift-redeemed').val('Yes');
1709                }else{
1710                    nc(".giftcard-con").removeClass('d-flex').addClass('d-none');
1711                    nc('#is-gift-redeemed').val('No');
1712                }
1713                
1714                //if reward is not empty
1715                if(reward > 0){
1716                    nc(".rewards-con").removeClass('d-none').addClass('d-flex');
1717                    nc(".basket_reward").empty().html('$' + reward);
1718                }else{
1719                    nc(".rewards-con").removeClass('d-flex').addClass('d-none');
1720                }
1721                
1722                //if basket due total is 0.00 and gift card balance not 0.00, remove credit card validation 
1723                if (parseFloat(total) === 0.00 && parseFloat(gift) !== 0.00) {
1724                    jQuery("#creditcardnum, #expirationmonth, #expirationyear").attr("data-required", "no");
1725                } else {
1726                    jQuery("#creditcardnum, #expirationmonth, #expirationyear").attr("data-required", "yes");
1727                }
1728            }
1729        });
1730    }       
1731});
1732
1733//Loyalty point Redeem
1734nc(document).on('click', '#loyal-redeem-btn', function(){
1735    event.preventDefault();
1736    var gift_card_chk  = nc("#redeem-gift-card").prop("checked") ? nc("#redeem-gift-card").val() : ""; //Yes
1737    var reward_chk     = nc("#redeem-loyal-point").prop("checked") ? nc("#redeem-loyal-point").val() : 0; 
1738    
1739    var islogin        = nc('#hid_isloggedin').val(); //check is login.
1740    
1741    if (islogin && islogin === "1") {
1742        var customer_type = 'Login';
1743    }else{
1744        var customer_type = 'Guest';
1745    }
1746    
1747    var delivery_type   = nc('#delivery-checkout .nav-item .nav-link.active').attr('data-delivery');
1748    var discountcode    = nc('#discount-code').val();
1749    var token           = nc("#hid_vaultid").val(); //token taken from hidden after updating
1750    var creditcardtype  = nc("#hid_creditcardtype").val(); //card type taken from hidden after adding creditcard.
1751    
1752    //Shipping
1753    var shipfirstname   = nc("#shipfirstname").val();
1754    var shiplastname    = nc("#shiplastname").val();
1755    var shipemail       = nc("#shipemail").val();
1756    var shipbirthdate   = nc("#shipbirthdate").val();
1757    var shipcompanyname = nc("#shipcompanyname").val();
1758    var shipaddress1    = nc("#shipaddress1").val();
1759    var shipaddress2    = nc("#shipaddress2").val();
1760    var shippostalcode  = nc("#shippostalcode").val();
1761    var shipcity        = nc("#shipcity").val();
1762    var shipstate       = nc("#shipstate").val();
1763    var shipphone       = nc("#shipphone").val();
1764    var shippingoption  = nc("#shipping-option").val(); //service
1765    var shippingmethod  = nc("#shipping-method").val(); //method
1766    var isgift          = nc("#isgift").prop("checked") ? nc("#isgift").val() : "";
1767    var giftnotes       = nc("#giftnotes").val();
1768    var emailaddress2   = nc("#emailaddress2").val();
1769    var notes           = nc("#notes").val();
1770
1771    //pickup 
1772    var pickupfirstname = nc("#pickupfirstname").val();
1773    var pickuplastname  = nc("#pickuplastname").val();
1774    var pickupemail     = nc("#pickupemail").val();  
1775    var birthdate       = nc("#birthdate").val();
1776    var checkout_pickuplocation = nc("#checkout_pickuplocation").val();
1777    
1778    //delivery
1779    var delifirstname   = nc("#delifirstname").val();
1780    var delilastname    = nc("#delilastname").val();
1781    var deliemail       = nc("#deliemail").val();
1782    var delicompanyname = nc("#delicompanyname").val();
1783    var deliaddress1    = nc("#deliaddress1").val();
1784    var deliaddress2    = nc("#deliaddress2").val();
1785    var delipostalcode  = nc("#delipostalcode").val();
1786    var delicity        = nc("#delicity").val();
1787    var delistate       = nc("#delistate").val();
1788    var deliphone       = nc("#deliphone").val();
1789    
1790    //PAYMENT/REVIEW
1791    var gift_card_num    = nc("#gift-card-num").val();
1792    var security_code    = nc("#security-code").val();
1793    var giftcard_id      = nc("#gifcrd_id").val();
1794    var giftcard_bal     = nc("#gifcrd_bal").val();
1795    //var useloyaltypoints = nc("#redeem-loyal-point").prop("checked") ? nc("#redeem-loyal-point").val() : 0;
1796    
1797    var creditcardnum   = nc("#hid_creditcardnum").val();
1798    var expitationmonth = nc("#hid_expirationmonth").val();
1799    var expitationyear  = nc("#hid_expirationyear").val();
1800    //var creditcardcvv2  = nc("#creditcardcvv2").val();
1801    var avsaddress      = nc("#avsaddress").val();
1802    var avspostalcode   = nc("#avspostalcode").val();
1803    var avscity         = nc("#avscity").val();
1804    var avsstate        = nc("#avsstate").val();
1805    
1806    //validation empty field 
1807    var errors = 0;
1808    nc('#loyal-point-sec :input[data-required = "yes"]').map(function(){
1809        if( !nc(this).val().trim()) {
1810            nc(this).addClass('error');
1811            errors++;
1812        } else if (nc(this).val()) {
1813            nc(this).removeClass('error');
1814        }   
1815    });
1816
1817    //Empty field validation.
1818    if(errors > 0){
1819        return false;
1820    }else{
1821        nc.ajax({
1822            type: "POST",
1823            url:""+nc('#admin_url').val()+"", 
1824           data: {
1825                action: "customize_redeem_now",
1826                result: "loyal_redeem_now",
1827                useloyaltypoints  : 1, //important
1828                gift_card_chk   : gift_card_chk, //important
1829                reward_chk      : reward_chk, //important
1830                giftcard_id     : giftcard_id,
1831                giftcard_bal    : giftcard_bal,
1832                delivery_type   : delivery_type,
1833                customer_type   : customer_type,
1834                discountcode    : discountcode,
1835                token           : token,
1836                creditcardtype  : creditcardtype,
1837                shipfirstname   : shipfirstname,
1838                shiplastname    : shiplastname,
1839                shipemail       : shipemail,
1840                shipbirthdate   : shipbirthdate,
1841                shipcompanyname : shipcompanyname,
1842                shipaddress1    : shipaddress1,
1843                shipaddress2    : shipaddress2,
1844                shippostalcode  : shippostalcode,
1845                shipcity        : shipcity,
1846                shipstate       : shipstate,
1847                shipphone       : shipphone,
1848                shippingoption  : shippingoption,
1849                shippingmethod  : shippingmethod,
1850                isgift          : isgift,
1851                giftnotes       : giftnotes, //no element
1852                emailaddress2   : emailaddress2,
1853                notes           : notes,
1854                pickupfirstname : pickupfirstname,
1855                pickuplastname  : pickuplastname,
1856                pickupemail     : pickupemail,
1857                birthdate       : birthdate,
1858                checkout_pickuplocation : checkout_pickuplocation,
1859                delifirstname   : delifirstname,
1860                delilastname    : delilastname,
1861                deliemail       : deliemail,
1862                delicompanyname : delicompanyname,
1863                deliaddress1    : deliaddress1,
1864                deliaddress2    : deliaddress2,
1865                delipostalcode  : delipostalcode,
1866                delicity        : delicity,
1867                delistate       : delistate,
1868                deliphone       : deliphone,
1869                gift_card_num   : gift_card_num,
1870                security_code   : security_code,
1871                creditcardnum   : creditcardnum,
1872                expitationmonth : expitationmonth,
1873                expitationyear  : expitationyear,
1874                //creditcardcvv2 : creditcardcvv2,
1875                avsaddress      : avsaddress,
1876                avspostalcode   : avspostalcode,
1877                avscity         : avscity,
1878                avsstate        : avsstate,
1879            },
1880            beforeSend: function(){
1881                nc('#loyal-redeem-btn').html('<i style="font-size: 16px;" class="fa fa-circle-thin me-2"></i>Loading...');
1882            },
1883            success: function(data){
1884                var splitted = data.split('===');
1885                if(data){
1886                    console.log(data);
1887                    
1888                    var subtotal = parseFloat(splitted[1]).toFixed(2);
1889                    var discount = parseFloat(splitted[2]).toFixed(2);
1890                    var deliveryfee = parseFloat(splitted[3]).toFixed(2);
1891                    var tax = parseFloat(splitted[4]).toFixed(2);
1892                    var total = parseFloat(splitted[5]).toFixed(2);
1893                    var gift = parseFloat(splitted[6]).toFixed(2);
1894                    var reward = parseFloat(splitted[7]).toFixed(2);
1895                    
1896                    nc(".sidebar_inventory_list").empty().html(splitted[0]);
1897                    nc(".basket_subtotal").empty().html('$' + subtotal);
1898                    nc(".basket_total").empty().html('$'+total);
1899                    
1900                    if (discount > 0) {
1901                        nc(".disc-con").removeClass('d-none').addClass('d-flex');
1902                        nc(".basket_discount").empty().html('$' + discount);
1903                    } else {
1904                        nc(".disc-con").removeClass('d-flex').addClass('d-none');
1905                    }
1906                    
1907                    if (deliveryfee > 0) {
1908                        nc(".deli-con").removeClass('d-none').addClass('d-flex');
1909                        nc(".basket_del_fee").empty().html('$' + deliveryfee);
1910                    } else {
1911                        nc(".deli-con").removeClass('d-flex').addClass('d-none');
1912                    }
1913                    
1914                    if (tax > 0) {
1915                        nc(".tax-con").removeClass('d-none').addClass('d-flex');
1916                        nc(".basket_tax").empty().html('$' + tax);
1917                    } else {
1918                        nc(".tax-con").removeClass('d-flex').addClass('d-none');
1919                    }
1920                    
1921                    //If GiftCardAmount is not empty
1922                    if(gift > 0){
1923                        nc(".giftcard-con").removeClass('d-none').addClass('d-flex');
1924                        nc(".basket_gift").empty().html('$' + gift);
1925                    }else{
1926                        nc(".giftcard-con").removeClass('d-flex').addClass('d-none');
1927                    }
1928                    
1929                    //if reward is not empty
1930                    if(reward > 0){
1931                        nc(".rewards-con").removeClass('d-none').addClass('d-flex');
1932                        nc(".basket_reward").empty().html('$' + reward);
1933                        
1934                        //Redeem message
1935                        nc('#loyal-redeem-btn').empty().html('<i class="fa fa-check me-2"></i> Redeemed');
1936                        nc('.loyalty-result').show().empty().html('<b>$'+reward+'</b> of your Rewards have been applied to this order.');
1937                        nc('#is-loyal-redeemed').val('Yes');
1938                    
1939                    }else{
1940                        nc(".rewards-con").removeClass('d-flex').addClass('d-none');
1941                        
1942                        //Redeem message
1943                        nc('#loyal-redeem-btn').empty().html('<i class="fa fa-check me-2"></i> Redeem');
1944                        nc('.loyalty-result').show().empty().html('You have <b>$'+reward+'</b> Rewards balance.');
1945                        nc('#is-loyal-redeemed').val('No');
1946                    }
1947                } 
1948            }
1949        });
1950    }
1951});
1952
1953//Coupon Discount
1954nc(document).on('click', '.coupon-btn', function(){
1955    event.preventDefault();
1956    var gift_card_chk  = nc("#redeem-gift-card").prop("checked") ? nc("#redeem-gift-card").val() : ""; //Yes
1957    var reward_chk     = nc("#redeem-loyal-point").prop("checked") ? nc("#redeem-loyal-point").val() : 0; 
1958    
1959    var islogin         = nc('#hid_isloggedin').val(); //check is login.
1960    
1961    if (islogin && islogin === "1") {
1962        var customer_type = 'Login';
1963    }else{
1964        var customer_type = 'Guest';
1965    }
1966    
1967    var delivery_type   = nc('#delivery-checkout .nav-item .nav-link.active').attr('data-delivery');
1968    var discountcode    = nc('#discount-code').val();
1969    var token           = nc("#hid_vaultid").val(); //token taken from hidden after updating
1970    var creditcardtype  = nc("#hid_creditcardtype").val(); //card type taken from hidden after adding creditcard.
1971    
1972    //Shipping
1973    var shipfirstname   = nc("#shipfirstname").val();
1974    var shiplastname    = nc("#shiplastname").val();
1975    var shipemail       = nc("#shipemail").val();
1976    var shipbirthdate   = nc("#shipbirthdate").val();
1977    var shipcompanyname = nc("#shipcompanyname").val();
1978    var shipaddress1    = nc("#shipaddress1").val();
1979    var shipaddress2    = nc("#shipaddress2").val();
1980    var shippostalcode  = nc("#shippostalcode").val();
1981    var shipcity        = nc("#shipcity").val();
1982    var shipstate       = nc("#shipstate").val();
1983    var shipphone       = nc("#shipphone").val();
1984    var shippingoption  = nc("#shipping-option").val(); //service
1985    var shippingmethod  = nc("#shipping-method").val(); //method
1986    var isgift          = nc("#isgift").prop("checked") ? nc("#isgift").val() : "";
1987    var giftnotes       = nc("#giftnotes").val();
1988    var emailaddress2   = nc("#emailaddress2").val();
1989    var notes           = nc("#notes").val();
1990
1991    //pickup 
1992    var pickupfirstname = nc("#pickupfirstname").val();
1993    var pickuplastname  = nc("#pickuplastname").val();
1994    var pickupemail     = nc("#pickupemail").val();  
1995    var birthdate       = nc("#birthdate").val();
1996    var checkout_pickuplocation = nc("#checkout_pickuplocation").val();
1997    
1998    //delivery
1999    var delifirstname   = nc("#delifirstname").val();
2000    var delilastname    = nc("#delilastname").val();
2001    var deliemail       = nc("#deliemail").val();
2002    var delicompanyname = nc("#delicompanyname").val();
2003    var deliaddress1    = nc("#deliaddress1").val();
2004    var deliaddress2    = nc("#deliaddress2").val();
2005    var delipostalcode  = nc("#delipostalcode").val();
2006    var delicity        = nc("#delicity").val();
2007    var delistate       = nc("#delistate").val();
2008    var deliphone       = nc("#deliphone").val();
2009    
2010    //PAYMENT/REVIEW
2011    var gift_card_num    = nc("#gift-card-num").val();
2012    var security_code    = nc("#security-code").val();
2013    var giftcard_id      = nc("#gifcrd_id").val();
2014    var giftcard_bal     = nc("#gifcrd_bal").val();
2015    var useloyaltypoints = nc("#redeem-loyal-point").prop("checked") ? nc("#redeem-loyal-point").val() : 0;
2016    
2017    var creditcardnum   = nc("#hid_creditcardnum").val();
2018    var expitationmonth = nc("#hid_expirationmonth").val();
2019    var expitationyear  = nc("#hid_expirationyear").val();
2020    //var creditcardcvv2  = nc("#creditcardcvv2").val();
2021    var avsaddress      = nc("#avsaddress").val();
2022    var avspostalcode   = nc("#avspostalcode").val();
2023    var avscity         = nc("#avscity").val();
2024    var avsstate        = nc("#avsstate").val();
2025
2026    //validation empty field 
2027    var errors = 0;
2028    nc('.discount-container :input[data-required = "yes"]').map(function(){
2029        if( !nc(this).val().trim()) {
2030            nc(this).addClass('error');
2031            errors++;
2032        } else if (nc(this).val()) {
2033            nc(this).removeClass('error');
2034        }   
2035    });
2036
2037    //Empty field validation.
2038    if(errors > 0){
2039        return false;
2040    }else{
2041        nc.ajax({
2042            type: "POST",
2043            url:""+nc('#admin_url').val()+"", 
2044           data: {
2045                action: "customize_redeem_now",
2046                result: "discount_now",
2047                useloyaltypoints  : useloyaltypoints,
2048                gift_card_chk   : gift_card_chk, //important
2049                reward_chk      : reward_chk, //important
2050                giftcard_id     : giftcard_id,
2051                giftcard_bal    : giftcard_bal,
2052                delivery_type   : delivery_type,
2053                customer_type   : customer_type,
2054                discountcode    : discountcode,
2055                token           : token,
2056                creditcardtype  : creditcardtype,
2057                shipfirstname   : shipfirstname,
2058                shiplastname    : shiplastname,
2059                shipemail       : shipemail,
2060                shipbirthdate   : shipbirthdate,
2061                shipcompanyname : shipcompanyname,
2062                shipaddress1    : shipaddress1,
2063                shipaddress2    : shipaddress2,
2064                shippostalcode  : shippostalcode,
2065                shipcity        : shipcity,
2066                shipstate       : shipstate,
2067                shipphone       : shipphone,
2068                shippingoption  : shippingoption,
2069                shippingmethod  : shippingmethod,
2070                isgift          : isgift,
2071                giftnotes       : giftnotes, //no element
2072                emailaddress2   : emailaddress2,
2073                notes           : notes,
2074                pickupfirstname : pickupfirstname,
2075                pickuplastname  : pickuplastname,
2076                pickupemail     : pickupemail,
2077                birthdate       : birthdate,
2078                checkout_pickuplocation : checkout_pickuplocation,
2079                delifirstname   : delifirstname,
2080                delilastname    : delilastname,
2081                deliemail       : deliemail,
2082                delicompanyname : delicompanyname,
2083                deliaddress1    : deliaddress1,
2084                deliaddress2    : deliaddress2,
2085                delipostalcode  : delipostalcode,
2086                delicity        : delicity,
2087                delistate       : delistate,
2088                deliphone       : deliphone,
2089                gift_card_num   : gift_card_num,
2090                security_code   : security_code,
2091                creditcardnum   : creditcardnum,
2092                expitationmonth : expitationmonth,
2093                expitationyear  : expitationyear,
2094                //creditcardcvv2 : creditcardcvv2,
2095                avsaddress      : avsaddress,
2096                avspostalcode   : avspostalcode,
2097                avscity         : avscity,
2098                avsstate        : avsstate,
2099            },
2100            beforeSend: function(){
2101                nc('.coupon-btn').html('<i style="font-size: 14px;" class="fa fa-circle-thin me-2"></i>Loading...');
2102            },
2103            success: function(data){
2104                var splitted = data.split('===');
2105                if(data){
2106                    console.log(data);
2107                    
2108                    if(splitted[8] > 0){ //If StatusCode not 0.
2109                        nc('.coupon-btn').empty().html('<i style="font-size: 14px;" class="fa fa-check me-2"></i>Applied');
2110                        nc('#errorwarn_discode').empty();
2111                        
2112                        var subtotal = parseFloat(splitted[1]).toFixed(2);
2113                        var discount = parseFloat(splitted[2]).toFixed(2);
2114                        var deliveryfee = parseFloat(splitted[3]).toFixed(2);
2115                        var tax = parseFloat(splitted[4]).toFixed(2);
2116                        var total = parseFloat(splitted[5]).toFixed(2);
2117                        var gift = parseFloat(splitted[6]).toFixed(2);
2118                        var reward = parseFloat(splitted[7]).toFixed(2);
2119                        
2120                        nc(".sidebar_inventory_list").empty().html(splitted[0]);
2121                        nc(".basket_subtotal").empty().html('$' + subtotal);
2122                        nc(".basket_total").empty().html('$'+total);
2123                        
2124                        if (discount > 0) {
2125                            nc(".disc-con").removeClass('d-none').addClass('d-flex');
2126                            nc(".basket_discount").empty().html('$' + discount);
2127                        } else {
2128                            nc(".disc-con").removeClass('d-flex').addClass('d-none');
2129                        }
2130                        
2131                        if (deliveryfee > 0) {
2132                            nc(".deli-con").removeClass('d-none').addClass('d-flex');
2133                            nc(".basket_del_fee").empty().html('$' + deliveryfee);
2134                        } else {
2135                            nc(".deli-con").removeClass('d-flex').addClass('d-none');
2136                        }
2137                        
2138                        if (tax > 0) {
2139                            nc(".tax-con").removeClass('d-none').addClass('d-flex');
2140                            nc(".basket_tax").empty().html('$' + tax);
2141                        } else {
2142                            nc(".tax-con").removeClass('d-flex').addClass('d-none');
2143                        }
2144                        
2145                        //If GiftCardAmount is not empty
2146                        if(gift > 0){
2147                            nc(".giftcard-con").removeClass('d-none').addClass('d-flex');
2148                            nc(".basket_gift").empty().html('$' + gift);
2149                        }else{
2150                            nc(".giftcard-con").removeClass('d-flex').addClass('d-none');
2151                        }
2152                        
2153                        //if reward is not empty
2154                        if(reward > 0){
2155                            nc(".rewards-con").removeClass('d-none').addClass('d-flex');
2156                            nc(".basket_reward").empty().html('$' + reward);
2157                        }else{
2158                            nc(".rewards-con").removeClass('d-flex').addClass('d-none');
2159                        }
2160                    
2161                    }else{
2162                        nc('.coupon-btn').empty().html('<i style="font-size: 14px;" class="fa fa-check me-2"></i>Apply');
2163                        nc('#errorwarn_discode').empty().html(splitted[9]);
2164                    } 
2165                } 
2166            }
2167        });
2168    }
2169});
2170
2171
2172//validate ship phone 
2173function validateDeliPhoneNumber(phoneNumber) {
2174    // Define the regular expression for the desired format
2175    var phoneRegex = /^\d{3}-\d{3}-\d{4}$/;
2176    // Test the phone number against the regular expression
2177    return phoneRegex.test(phoneNumber);
2178}
2179
2180//Validate Pickup Phone field and  to phone format
2181nc('#deliphone').on('blur',function(){
2182    var pickupphone = jQuery('#deliphone').val();
2183    var maxCount = jQuery('#deliphone').attr('maxlength');
2184    
2185    //var isValid = validateDeliPhoneNumber(pickupphone);
2186    var onlynumber = pickupphone.replace(/\D/g, ''); // Remove non-numeric characters
2187    var isValid = onlynumber.length; //validateDeliPhoneNumber(pickupphone);
2188    var numbers = '';
2189
2190    if (isValid > 12) {               
2191           jQuery('#errorwarn_deliphone').hide();
2192    } else {
2193
2194       if( pickupphone.length > 0 ){
2195            var numbers = pickupphone.replace(/\D/g, ''); // Remove non-numeric characters
2196            // Format the number as XXX-XXX-XXXX
2197            if (numbers.length >= 3) {
2198                numbers = numbers.substring(0, 3) + '-' + numbers.substring(3);
2199            }
2200            if (numbers.length >= 7) {
2201                numbers = numbers.substring(0, 7) + '-' + numbers.substring(7);
2202            }         
2203            //Converted phone display into input field
2204            jQuery('#deliphone').val(numbers);
2205            //After change format check validation
2206            var isValid_new = validateDeliPhoneNumber(numbers);
2207            if (isValid_new) {                
2208                jQuery('#errorwarn_deliphone').hide();
2209            } else {
2210                jQuery('#errorwarn_deliphone').show();
2211                jQuery("#errorwarn_deliphone").html("Invalid phone number. Please use the format XXX-XXX-XXXX.");
2212            }
2213        }else{
2214            jQuery('#errorwarn_deliphone').hide();
2215        }
2216        
2217        //Maximum limit phone is 10 digit. Total:10
2218        if(numbers.length > maxCount){
2219            jQuery(this).val(jQuery(this).val().substring(0,maxCount));
2220        }
2221    }   
2222});
2223
2224//Payment billing address Zipcode and City auto fill input fields from API RetrieveCityStateForZipcode.
2225nc('#delipostalcode').on('blur',function(){
2226    var delipostalcode = jQuery('#delipostalcode').val();
2227    nc.ajax({
2228        type: "POST",
2229        url:""+nc('#admin_url').val()+"", 
2230        data:"action=custom_retrieve_city_state_zipcode&result=zipcode&zipcode="+delipostalcode, 
2231        beforeSend: function(){                 
2232             jQuery("#delicity").attr("placeholder", "Loading...");
2233             jQuery("#delistate").attr("placeholder", "Loading...");  
2234             jQuery('#errorwarn_postal_deli').hide();          
2235        },              
2236        success: function(msg){                      
2237                
2238            if(msg){  
2239
2240                //alert(msg);
2241                //console.log(msg);
2242
2243                var splitted = msg.split('==='); 
2244                var splitted_state_available = msg.split('###');      
2245
2246                //if(splitted[2] ){
2247                    nc('#delicity').empty();
2248                    nc('#delicity').val(splitted[2]); //city
2249                //}
2250
2251                //if(splitted[3] ){
2252                    nc('#delistate').empty();
2253                    nc('#delistate').val(splitted[3]); //state   
2254                //}   
2255
2256                if(splitted_state_available[1] =='Yes'){
2257                    //Check state available
2258                    nc('#delistate_available').empty();
2259                    nc('#delistate_available').val(splitted_state_available[1]);
2260
2261                    //jQuery("#delistate").removeClass("error");
2262                    jQuery('#errorwarn_postal_deli').hide();
2263
2264                }else if(splitted_state_available[1] =='No'){
2265                    //Check state available
2266                    nc('#delistate_available').empty();
2267                    nc('#delistate_available').val(splitted_state_available[1]);
2268
2269                    //jQuery("#delistate").addClass("error"); 
2270                    var state_name_available=""
2271                    if(splitted_state_available[2]!="")  {
2272
2273                        //state_name_available=splitted_state_available[2];
2274                        //jQuery('#errorwarn_postal_deli').show();
2275                        //jQuery("#errorwarn_postal_deli").html("We currently cannot ship items with alcohol to "+state_name_available+".");
2276                    }
2277                                 
2278                }else{
2279                    //Check state available
2280                    nc('#delistate_available').empty();
2281                    nc('#delistate_available').val(splitted_state_available[1]);
2282
2283                    jQuery("#avscity").attr("placeholder", "City");
2284                    jQuery("#avsstate").attr("placeholder", "State");   
2285
2286                    jQuery('#avserrorwarn_postal').show();
2287                    jQuery("#avserrorwarn_postal").html(msg);
2288                }
2289            }     
2290        }
2291    });
2292});
2293
2294//Get payment bill city 
2295nc('#delicity,#delistate').on('blur',function(){
2296    var delicity=jQuery('#delicity').val();
2297    var delipostalcode = jQuery('#delipostalcode').val();
2298    nc.ajax({
2299        type: "POST",
2300        url:""+nc('#admin_url').val()+"", 
2301        data:"action=custom_retrieve_city_state_zipcode&result=zipcode&zipcode="+delipostalcode+"&city="+delicity, 
2302        beforeSend: function(){
2303            //jQuery("#delicity").attr("placeholder", "Loading...");
2304            //jQuery("#delistate").attr("placeholder", "Loading...");  
2305            jQuery('#errorwarn_postal_deli').hide();   
2306        },              
2307        success: function(msg){              
2308
2309            if(msg){   
2310                //alert(msg);
2311
2312                //console.log(msg);
2313                var splitted = msg.split('==='); 
2314                var splitted_state_available = msg.split('###'); 
2315
2316                if(splitted[2] ){             
2317                  nc('#delicity').empty();
2318                  nc('#delicity').val(splitted[2]);
2319                }  
2320                if(splitted[3] ){
2321                  nc('#delistate').empty();
2322                  nc('#delistate').val(splitted[3]);     
2323                }   
2324
2325                if(splitted_state_available[1] =='Yes'){
2326
2327                    //Check state available
2328                    nc('#delistate_available').empty();
2329                    nc('#delistate_available').val(splitted_state_available[1]);
2330                       
2331                    //jQuery("#delistate").removeClass("error");
2332                    jQuery('#errorwarn_postal_deli').hide();
2333
2334                }else if(splitted_state_available[1] =='No'){
2335                    //Check state available
2336                    nc('#delistate_available').empty();
2337                    nc('#delistate_available').val(splitted_state_available[1]);
2338
2339                    //jQuery("#delistate").addClass("error"); 
2340                    var state_name_available=""
2341                    if(splitted_state_available[2]!="")  {
2342
2343                        //state_name_available=splitted_state_available[2];
2344                        //jQuery('#errorwarn_postal_deli').show();
2345                        //jQuery("#errorwarn_postal_deli").html("We currently cannot ship items with alcohol to "+state_name_available+".");
2346                    }
2347                                 
2348                }else{
2349                    //Check state available
2350                    nc('#delistate_available').empty();
2351                    nc('#delistate_available').val('');
2352 
2353                    jQuery('#errorwarn_postal_deli').show();
2354                    jQuery("#errorwarn_postal_deli").html(msg);
2355                }   
2356            }     
2357        }
2358    });
2359});
2360
2361//if giftcard or delivery note uncheck, empty input field.
2362nc("#isgift").change(function () {
2363    if (!nc(this).prop("checked")) {
2364        nc('#shipping #giftnotes').val('');
2365        nc('#shipping #emailaddress2').val('');
2366    }
2367});
2368
2369nc("#isdelivery").change(function () {
2370    if (!nc(this).prop("checked")) {
2371        nc('#shipping #notes').val('');
2372    }
2373});
2374
2375//if giftcard number uncheck, emtpy input field
2376nc("#redeem-gift-card").change(function () {
2377    if (!nc(this).prop("checked")) {
2378        nc('#gift-card-num').val('');
2379        nc('#security-code').val('');
2380        
2381        //call webgetcheckoutinfo api
2382        calling_getwebcheckoutinfo();
2383    }
2384});
2385//end
2386
2387//validate input number
2388nc(document).on('input', 'input[type="number"]', function () {
2389    let cleaned = nc(this).val().replace(/[^0-9]/g, '');
2390    nc(this).val(cleaned);
2391});
2392
2393}); //******End of main document******
2394
2395//Calling shipping service and shipping method.
2396function get_shipping_service_and_method_result(){
2397    var checkInterval = setInterval(function () {
2398        var shipstate = nc('#shipstate').val();
2399        //alert(shipstate);
2400        
2401        if (shipstate !== "") {
2402            clearInterval(checkInterval); // Stop checking
2403            
2404            nc.ajax({
2405                type: "POST",
2406                url:""+nc('#admin_url').val()+"", 
2407                data:"action=custom_retrieve_shipservi_shipmethd&result=shipservimethod&shipstate="+shipstate, 
2408                beforeSend: function(){                 
2409                     //jQuery("#shipcity").attr("placeholder", "Loading...");
2410                     //jQuery("#shipstate").attr("placeholder", "Loading...");  
2411                },              
2412                success: function(data){                      
2413                    if(data){  
2414                        //alert(data);
2415                        console.log(data);
2416                        jQuery('#errorwarn_postal_shservmethd').hide(); //Hide error warning.
2417                        var splitted = data.split('==='); 
2418                        
2419                        // Auto-select the shipping option
2420                        if(splitted[0]){
2421                            nc("#shipping-option").val(splitted[0]).change();
2422                        }
2423                        
2424                        // Auto-select the shipping method
2425                        if(splitted[1]){
2426                            nc("#shipping-method").val(splitted[1]).change();
2427                        }
2428                    }else{
2429                        jQuery('#errorwarn_postal_shservmethd').show();
2430                        jQuery("#errorwarn_postal_shservmethd").html("Please enter valid Zip Code / City.");
2431                    }    
2432                }
2433            });
2434        }else{
2435            jQuery('#errorwarn_postal_shservmethd').show();
2436            jQuery("#errorwarn_postal_shservmethd").html("Please enter valid Zip Code / City.");
2437        }
2438    }, 100); // Check every 100ms
2439}
2440
2441//Order History "view details" click slide open.
2442function openOrderHistory(id) {
2443    var nc = jQuery.noConflict();
2444    nc('.c7-history-'+id).css('right','0px');
2445}
2446
2447//close order history view details X click.
2448function closeHistory() {
2449    var nc = jQuery.noConflict();
2450    nc('.c7-cart.order').css('right','-510px');
2451}
2452
2453//Calling Web Get Checkout Info
2454function calling_getwebcheckoutinfo(){
2455    
2456    var islogin = nc('#hid_isloggedin').val(); //check is login.
2457    
2458    if (islogin && islogin === "1") {
2459        var customer_type = 'Login';
2460    }else{
2461        var customer_type = 'Guest';
2462    } 
2463    
2464    var delivery_type   = nc('#delivery-checkout .nav-item .nav-link.active').attr('data-delivery');
2465    var discountcode    = nc('#discount-code').val();
2466    var token           = nc("#hid_vaultid").val(); //token taken from hidden after updating
2467    var creditcardtype  = nc("#hid_creditcardtype").val(); //card type taken from hidden after adding creditcard.
2468    
2469    //Shipping
2470    var shipfirstname   = nc("#shipfirstname").val();
2471    var shiplastname    = nc("#shiplastname").val();
2472    var shipemail       = nc("#shipemail").val();
2473    var shipbirthdate   = nc("#shipbirthdate").val();
2474    var shipcompanyname = nc("#shipcompanyname").val();
2475    var shipaddress1    = nc("#shipaddress1").val();
2476    var shipaddress2    = nc("#shipaddress2").val();
2477    var shippostalcode  = nc("#shippostalcode").val();
2478    var shipcity        = nc("#shipcity").val();
2479    var shipstate       = nc("#shipstate").val();
2480    var shipphone       = nc("#shipphone").val();
2481    var shippingoption  = nc("#shipping-option").val(); //service
2482    var shippingmethod  = nc("#shipping-method").val(); //method
2483    var isgift          = nc("#isgift").prop("checked") ? nc("#isgift").val() : "";
2484    var giftnotes       = nc("#giftnotes").val();
2485    var emailaddress2   = nc("#emailaddress2").val();
2486    var notes           = nc("#notes").val();
2487
2488    //pickup 
2489    var pickupfirstname = nc("#pickupfirstname").val();
2490    var pickuplastname  = nc("#pickuplastname").val();
2491    var pickupemail     = nc("#pickupemail").val();  
2492    var birthdate       = nc("#birthdate").val();
2493    var checkout_pickuplocation = nc("#checkout_pickuplocation").val();
2494    
2495    //delivery
2496    var delifirstname   = nc("#delifirstname").val();
2497    var delilastname    = nc("#delilastname").val();
2498    var deliemail       = nc("#deliemail").val();
2499    var delicompanyname = nc("#delicompanyname").val();
2500    var deliaddress1    = nc("#deliaddress1").val();
2501    var deliaddress2    = nc("#deliaddress2").val();
2502    var delipostalcode  = nc("#delipostalcode").val();
2503    var delicity        = nc("#delicity").val();
2504    var delistate       = nc("#delistate").val();
2505    var deliphone       = nc("#deliphone").val();
2506    
2507    //PAYMENT/REVIEW
2508    var gift_card_num    = nc("#gift-card-num").val();
2509    var security_code    = nc("#security-code").val();
2510    var giftcard_id      = nc("#gifcrd_id").val();
2511    var giftcard_bal     = nc("#gifcrd_bal").val();
2512    var useloyaltypoints = nc("#redeem-loyal-point").prop("checked") ? nc("#redeem-loyal-point").val() : 0;
2513    
2514    var creditcardnum   = nc("#hid_creditcardnum").val();
2515    var expitationmonth = nc("#hid_expirationmonth").val();
2516    var expitationyear  = nc("#hid_expirationyear").val();
2517    //var creditcardcvv2  = nc("#creditcardcvv2").val();
2518    var avsaddress      = nc("#avsaddress").val();
2519    var avspostalcode   = nc("#avspostalcode").val();
2520    var avscity         = nc("#avscity").val();
2521    var avsstate        = nc("#avsstate").val();
2522    var allocation_id   = nc("#allocation_id").val();
2523    
2524    nc.ajax({
2525        type: "POST",
2526        url:""+nc('#admin_url').val()+"", 
2527        data: {
2528            action: "customize_calling_webgetcheckoutinfo",
2529            result: "call_webgetcheckout",
2530            delivery_type   : delivery_type,
2531            customer_type   : customer_type,
2532            discountcode    : discountcode,
2533            token           : token,
2534            creditcardtype  : creditcardtype,
2535            shipfirstname   : shipfirstname,
2536            shiplastname    : shiplastname,
2537            shipemail       : shipemail,
2538            shipbirthdate   : shipbirthdate,
2539            shipcompanyname : shipcompanyname,
2540            shipaddress1    : shipaddress1,
2541            shipaddress2    : shipaddress2,
2542            shippostalcode  : shippostalcode,
2543            shipcity        : shipcity,
2544            shipstate       : shipstate,
2545            shipphone       : shipphone,
2546            shippingoption  : shippingoption,
2547            shippingmethod  : shippingmethod,
2548            isgift          : isgift,
2549            giftnotes       : giftnotes, //no element
2550            emailaddress2   : emailaddress2,
2551            notes           : notes,
2552            pickupfirstname : pickupfirstname,
2553            pickuplastname  : pickuplastname,
2554            pickupemail     : pickupemail,
2555            birthdate       : birthdate,
2556            checkout_pickuplocation : checkout_pickuplocation,
2557            delifirstname   : delifirstname,
2558            delilastname    : delilastname,
2559            deliemail       : deliemail,
2560            delicompanyname : delicompanyname,
2561            deliaddress1    : deliaddress1,
2562            deliaddress2    : deliaddress2,
2563            delipostalcode  : delipostalcode,
2564            delicity        : delicity,
2565            delistate       : delistate,
2566            deliphone       : deliphone,
2567            gift_card_num   : gift_card_num,
2568            security_code   : security_code,
2569            giftcard_id     : giftcard_id,
2570            giftcard_bal    : giftcard_bal,
2571            useloyaltypoints: useloyaltypoints,
2572            creditcardnum   : creditcardnum,
2573            expitationmonth : expitationmonth,
2574            expitationyear  : expitationyear,
2575            //creditcardcvv2 : creditcardcvv2,
2576            avsaddress      : avsaddress,
2577            avspostalcode   : avspostalcode,
2578            avscity         : avscity,
2579            avsstate        : avsstate,
2580            allocation_id   : allocation_id,
2581        },
2582        beforeSend: function(){
2583            //alert('before send');
2584        },
2585        success: function(data){
2586            var splitted = data.split('===');
2587            if(data){
2588                console.log(data);
2589                
2590                //Convert from loading.. to calculate delivery fee text again.
2591                nc("#cal-deli-fee").empty().html('<i style="font-size: 14px;" class="fa fa-check me-2"></i>Calculate Delivery Fee');
2592                
2593                var subtotal = parseFloat(splitted[1]).toFixed(2);
2594                var discount = parseFloat(splitted[2]).toFixed(2);
2595                var deliveryfee = parseFloat(splitted[3]).toFixed(2);
2596                var tax = parseFloat(splitted[4]).toFixed(2);
2597                var total = parseFloat(splitted[5]).toFixed(2);
2598                var gift = parseFloat(splitted[6]).toFixed(2);
2599                var reward = parseFloat(splitted[7]).toFixed(2);
2600                
2601                nc(".sidebar_inventory_list").empty().html(splitted[0]);
2602                nc(".basket_subtotal").empty().html('$' + subtotal);
2603                nc(".basket_total").empty().html('$'+total);
2604                
2605                if (discount > 0) {
2606                    nc(".disc-con").removeClass('d-none').addClass('d-flex');
2607                    nc(".basket_discount").empty().html('$' + discount);
2608                } else {
2609                    nc(".disc-con").removeClass('d-flex').addClass('d-none');
2610                }
2611                
2612                if (deliveryfee > 0) {
2613                    nc(".deli-con").removeClass('d-none').addClass('d-flex');
2614                    nc(".basket_del_fee").empty().html('$' + deliveryfee);
2615                } else {
2616                    nc(".deli-con").removeClass('d-flex').addClass('d-none');
2617                }
2618                
2619                if (tax > 0) {
2620                    nc(".tax-con").removeClass('d-none').addClass('d-flex');
2621                    nc(".basket_tax").empty().html('$' + tax);
2622                } else {
2623                    nc(".tax-con").removeClass('d-flex').addClass('d-none');
2624                }
2625                
2626                //If GiftCardAmount is not empty
2627                if(gift > 0){
2628                    nc(".giftcard-con").removeClass('d-none').addClass('d-flex');
2629                    nc(".basket_gift").empty().html('$' + gift);
2630                }else{
2631                    nc(".giftcard-con").removeClass('d-flex').addClass('d-none');
2632                }
2633                
2634                //if reward is not empty
2635                if(reward > 0){
2636                    nc(".rewards-con").removeClass('d-none').addClass('d-flex');
2637                    nc(".basket_reward").empty().html('$' + reward);
2638                }else{
2639                    nc(".rewards-con").removeClass('d-flex').addClass('d-none');
2640                }
2641                
2642                //Hide/show not delivery message for Wisconsin
2643                if(splitted[8] > 0){
2644                    
2645                    nc(".amount-summary").show();
2646                    nc(".error_desc").hide('slow');
2647                    
2648                    if (discount > 0) {
2649                        nc(".disc-con").removeClass('d-none').addClass('d-flex');
2650                    } else {
2651                        nc(".disc-con").removeClass('d-flex').addClass('d-none');
2652                    }
2653                    
2654                    if (gift > 0) {
2655                        nc(".giftcard-con").removeClass('d-none').addClass('d-flex');
2656                    } else {
2657                        nc(".giftcard-con").removeClass('d-flex').addClass('d-none');
2658                    }
2659                    
2660                    if (reward > 0) {
2661                        nc(".rewards-con").removeClass('d-none').addClass('d-flex');
2662                    } else {
2663                        nc(".rewards-con").removeClass('d-flex').addClass('d-none');
2664                    }
2665                    
2666                    if (deliveryfee > 0) {
2667                        nc(".deli-con").removeClass('d-none').addClass('d-flex');
2668                    } else {
2669                        nc(".deli-con").removeClass('d-flex').addClass('d-none');
2670                    }
2671                    
2672                    if (tax > 0) {
2673                        nc(".tax-con").removeClass('d-none').addClass('d-flex');
2674                    } else {
2675                        nc(".tax-con").removeClass('d-flex').addClass('d-none');
2676                    }
2677                    
2678                }else{
2679                    nc(".amount-summary").hide('slow');
2680                    nc(".error_desc").show();
2681                }
2682                
2683            } 
2684        }
2685    });
2686}
2687
2688//Replace quantity restrict if greater then max
2689function stopreplaceqty(input, max) {
2690    const $input = nc(input); // Make sure you're using jQuery
2691    let value = parseInt($input.val(), 10);
2692
2693    if (value > max) {
2694        $input.val(max);
2695    }
2696}
2697
2698//Cart checkout page slider for (you might also like and Recent)
2699// slick slider
2700var pro_breakpoint = {
2701  // Small screen / phone
2702  sm: 576,   // Updated to match typical bootstrap sm breakpoint
2703  // Medium screen / tablet
2704  md: 768,
2705  // Large screen / desktop
2706  lg: 992,
2707  // Extra large screen / wide desktop
2708  xl: 1200
2709};
2710
2711var nc = jQuery.noConflict();
2712nc(window).on('load', function() { 
2713    var $sliders = nc('#checkout-slick-recent, #checkout-slick-like');
2714
2715    // Initialize Slick
2716    $sliders.slick({
2717        autoplay: false,
2718        autoplaySpeed: 1000,
2719        pauseOnFocus: false,
2720        draggable: true,
2721        infinite: true,
2722        dots: false,
2723        arrows: false,
2724        speed: 1000,
2725        mobileFirst: true,
2726        slidesToShow: 1,
2727        slidesToScroll: 1,
2728        responsive: [
2729            {
2730                breakpoint: pro_breakpoint.sm,
2731                settings: {
2732                    slidesToShow: 1,
2733                    slidesToScroll: 1,
2734                    arrows: true
2735                }
2736            },
2737            {
2738                breakpoint: pro_breakpoint.md,
2739                settings: {
2740                    slidesToShow: 3,
2741                    slidesToScroll: 1,
2742                    arrows: true
2743                }
2744            },
2745            {
2746                breakpoint: pro_breakpoint.lg,
2747                settings: {
2748                    slidesToShow: 4,
2749                    slidesToScroll: 1,
2750                    arrows: true
2751                }
2752            },
2753            {
2754                breakpoint: pro_breakpoint.xl,
2755                settings: {
2756                    slidesToShow: 4,
2757                    slidesToScroll: 1,
2758                    arrows: true
2759                }
2760            }
2761        ]
2762    });
2763
2764    //Fix width when switching tabs, Run this when a Bootstrap 5 tab becomes visible
2765    nc('a[data-bs-toggle="tab"]').on('shown.bs.tab', function (e) {
2766        const target = nc(e.target).attr("href");
2767
2768        if (target === '#cart-checkout' && $sliders.hasClass('slick-initialized')) {
2769            let tries = 0;
2770            let interval = setInterval(function() {
2771                const containerWidth = nc(target).width();
2772                if (containerWidth > 0 || tries > 10) {
2773                    clearInterval(interval);
2774                    $sliders.slick('refresh');
2775                }
2776                tries++;
2777            }, 100); // check every 100ms up to 1 second
2778        }
2779    });
2780});
2781//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.