 <script>
    ;(function($){
        "use strict";
        $(document).ready(function () {
            // MAILCHIMP
            if ($(".mailchimp").length > 0) {
                $(".mailchimp").ajaxChimp({
                    callback: mailchimpCallback,
                    url: "<?php echo esc_html__( $form_action_url_new ); ?>"
                });
            }
            $(".memail").on("focus", function () {
                $(".mchimp-errmessage").fadeOut();
                $(".mchimp-sucmessage").fadeOut();
            });
            $(".memail").on("keydown", function () {
                $(".mchimp-errmessage").fadeOut();
                $(".mchimp-sucmessage").fadeOut();
            });
            $(".memail").on("click", function () {
                $(".memail").val("");
            });

            function mailchimpCallback(resp) {
                if (resp.result === "success") {
                    setTimeout(function() {
                        window.location.href = "<?php echo esc_html__( $page_redirect_url_new ); ?>"
                    }, 3000);                        
                    $(".mchimp-sucmessage").html('<?php if( ! $option_subscribe_success_msg_new == '' ) : echo esc_attr( $option_subscribe_success_msg_new ); else : echo esc_html__('Thank you for subscribe.', 'envy-chimp'); endif; ?>').fadeIn(500);
                } else if (resp.result === "error") {
                    $(".mchimp-errmessage").html(resp.msg).fadeIn(500);
                }
            }
        });
    })(jQuery)
</script>
