/* global fp_rac_general_tab_obj */
jQuery(function ($) {

    var Buddypress_actions = {
        init: function () {
            this.trigger_on_page_load();
            $(document).on('change', '#rs_enable_points_for_bp_post_create', this.toggle_bp_post_create);
            $(document).on('change', '#rs_enable_points_for_bp_postcomment', this.toggle_bp_page_comment);
            $(document).on('change', '#rs_enable_points_for_bp_group_create', this.toggle_bp_group_create);
        },
      
        trigger_on_page_load: function () {
            this.toggle_bp_post_create_action('#rs_enable_points_for_bp_post_create');
            this.toggle_bp_page_comment_action('#rs_enable_points_for_bp_postcomment');
            this.toggle_bp_group_create_action('#rs_enable_points_for_bp_group_create');
        },
        
        toggle_bp_post_create: function (event) {
            event.preventDefault();
            var $this = $(event.currentTarget);
            Buddypress_actions.toggle_bp_post_create_action($this);
        },
        
        toggle_bp_page_comment: function (event) {
            event.preventDefault();
            var $this = $(event.currentTarget);
            Buddypress_actions.toggle_bp_page_comment_action($this);
        },
        toggle_bp_group_create: function (event) {
            event.preventDefault();
            var $this = $(event.currentTarget);
            Buddypress_actions.toggle_bp_group_create_action($this);
        },
        
        toggle_bp_post_create_action: function($this) {
             var bool = $($this).is(':checked');
             if(bool==true){
                 $('#rs_points_for_bp_post_create').parent().parent().show();
             } else {
                 $('#rs_points_for_bp_post_create').parent().parent().hide();
             }
        },
        
        toggle_bp_page_comment_action : function ( $this ) {
            var bool = $ ( $this ).is ( ':checked' ) ;
            if ( bool == true ) {
                $ ( '#rs_points_for_bp_postcomment' ).parent ().parent ().show () ;
            } else {
                $ ( '#rs_points_for_bp_postcomment' ).parent ().parent ().hide () ;
            }
        } ,

        toggle_bp_group_create_action : function ( $this ) {
            var bool = $ ( $this ).is ( ':checked' ) ;
            if ( bool == true ) {
                $ ( '#rs_points_for_bp_group_create' ).parent ().parent ().show () ;
                $ ( '#rs_points_for_bp_group_create_limit' ).parent ().parent ().show () ;
            } else {  
                $ ( '#rs_points_for_bp_group_create' ).parent ().parent ().hide () ;
                $ ( '#rs_points_for_bp_group_create_limit' ).parent ().parent ().hide () ;
            }
        } ,
    };
    Buddypress_actions.init();
});
