(function($){
    var $document = $(document);
    var $config_block = $('#pp_config_block');

    $document.off('change', 'input[name="on_payment_method"]');
    $document.on('change', 'input[name="on_payment_method"]', function(ev){
        ev.stopPropagation();

        var $current_plugin = $(this);
        $config_block.hide();
        $config_block.empty();

        var plugin_id = $current_plugin.val();

        if (plugin_id !== '0') {
            $.coreUtilites.ajaxRequest(
                {
                    subject: 'admin',
                    action: 'ajax_action_payment_get_config_block',
                    pp_id: plugin_id,
                    token: $('#token').val()
                },
                function(data) {
                    if (data.status == 'success') {
                        $config_block.html(data.message);
                        $config_block.show();
                    }
                }
            );

        }

        return false;
    });

    $document.ready(function(){
        var $changed = $('input[name="on_payment_method"]:checked');
        var pp_id = $changed.val();
        if (pp_id !=='0') {
            $.coreUtilites.ajaxRequest(
                {
                    subject: 'admin',
                    action: 'ajax_action_payment_get_config_block',
                    pp_id: pp_id,
                    token: $('#token').val()
                },
                function(data) {
                    if (data.status == 'success') {
                        $config_block.html(data.message);
                        $config_block.show();
                    }
                }
            );
        }
    });

})(SWjQuery);