
    // Test Connection AJAX
    $(document).on('click', '#ns-test-connection-btn', function() {
        var btn = $(this);
        var originalText = btn.text();
        var form = $('#netsuite-settings-form');
        btn.prop('disabled', true).text('Testing...');
        $.ajax({
            url: $(this).data('url'),
            type: 'POST',
            data: form.serialize(),
            dataType: 'json',
            success: function(response) {
                if (response.success) {
                    $('#connection-result').html('<div class="alert alert-success">' + response.message + '</div>');
                } else {
                    $('#connection-result').html('<div class="alert alert-danger">' + response.message + '</div>');
                }
            },
            error: function() {
                $('#connection-result').html('<div class="alert alert-danger">Connection test failed</div>');
            },
            complete: function() {
                btn.prop('disabled', false).text(originalText);
            }
        });
    });
