function Rich_Web_Forms_Added_Theme() {
    jQuery('.Rich_Web_Forms_Content_Data1_Theme').css('display', 'none');
    jQuery('.Rich_Web_Forms_Add_Theme').addClass('Rich_Web_Forms_Add_ThemeAnim');
    jQuery('.Rich_Web_Forms_Content_Data2_Theme').css('display', 'block');
    jQuery('.Rich_Web_Forms_Save_Theme').addClass('Rich_Web_Forms_Save_ThemeAnim');
    jQuery('.Rich_Web_Forms_Cancel_Theme').addClass('Rich_Web_Forms_Cancel_ThemeAnim');

    jQuery('input.alpha-color-picker').alphaColorPicker();
    jQuery('.wp-color-result').attr('title', 'Select');
    jQuery('.wp-color-result').attr('data-current', 'Selected');
    Rich_Web_Forms_RangeSlider();
}

function Rich_Web_Forms_Canceled_Theme() {
    location.reload();
}

function Rich_Web_Forms_Edit_Theme(Rich_Web_Forms_T_ID) {
    var ajaxurl = rw_form_json_object.ajaxurl;
    var data = {
        action: 'Rich_Web_Forms_Edit_Theme1',
        rw_form_nonce_field: rw_form_json_object.rw_forms_nonce,
        foobar: Rich_Web_Forms_T_ID,
    };
    jQuery.post(ajaxurl, data, function(response) {
        if (response.success !== true) {
            console.error("Not valid nonce");
            return false;
        }
        var responseData = response.data;
        for (const [key, value] of Object.entries(responseData)) {
            switch (key) {
                case "id":
                    break;
                case "Rich_Web_Forms_T_BoxShShow":
                case "Rich_Web_Forms_T_TBHBg":
                case "Rich_Web_Forms_T_TAHBg":
                case "Rich_Web_Forms_T_SMHBg":
                    var rwtoggle = value == "on" ? true : false;
                    jQuery(`#${key}`).attr('checked', rwtoggle);
                    break;
                case "Rich_Web_Forms_T_LBC":
                    var rwtoggle = value.length != 7 ? value + ')' : value;
                    jQuery(`#${key}`).val(rwtoggle);
                    break;
                default:
                    jQuery(`#${key}`).val(value);
                    break;
            }
        }
        jQuery('.Rich_Web_Contact_Form_Col1').alphaColorPicker();
        jQuery('.wp-color-result').attr('title', 'Select');
        jQuery('.wp-color-result').attr('data-current', 'Selected');
        Rich_Web_Forms_RangeSlider();
    })

    var ajaxurl = rw_form_json_object.ajaxurl;
    var data = {
        action: 'Rich_Web_Forms_Edit_Theme2',
        rw_form_nonce_field: rw_form_json_object.rw_forms_nonce,
        foobar: Rich_Web_Forms_T_ID,
    };
    jQuery.post(ajaxurl, data, function(response) {
        if (response.success !== true) {
            console.error("Not valid nonce");
            return false;
        }
        var responseData = response.data;
        for (const [key, value] of Object.entries(responseData)) {
            switch (key) {
                case "id":
                case "Rich_Web_Forms_T_RBCBC":
                case "Rich_Web_Forms_T_RBCC":
                    break;
                case "Rich_Web_Forms_T_EBHBg":
                    var rwtoggle = value == "on" ? true : false;
                    jQuery(`#${key}`).attr('checked', rwtoggle);
                    break;
                case "Rich_Web_Forms_T_DC":
                    var rwtoggle = value.length != 7 ? value + ')' : value;
                    jQuery(`#${key}`).val(rwtoggle);
                    break;
                default:
                    jQuery(`#${key}`).val(value);
                    break;
            }
        }
        jQuery('.Rich_Web_Contact_Form_Col2').alphaColorPicker();
        jQuery('.wp-color-result').attr('title', 'Select');
        jQuery('.wp-color-result').attr('data-current', 'Selected');
        Rich_Web_Forms_RangeSlider();
    })

    var ajaxurl = rw_form_json_object.ajaxurl;
    var data = {
        action: 'Rich_Web_Forms_Edit_Theme3',
        rw_form_nonce_field: rw_form_json_object.rw_forms_nonce,
        foobar: Rich_Web_Forms_T_ID,
    };
    jQuery.post(ajaxurl, data, function(response) {
        if (response.success !== true) {
            console.error("Not valid nonce");
            return false;
        }
        var responseData = response.data;
        jQuery('#Rich_Web_Forms_T_DF').val(responseData["Rich_Web_Forms_T_01"]);
        jQuery('#Rich_Web_Forms_T_MapW').val(responseData["Rich_Web_Forms_T_02"]);
        jQuery('#Rich_Web_Forms_T_MapH').val(responseData["Rich_Web_Forms_T_03"]);
        Rich_Web_Forms_RangeSlider();
    })
    jQuery('#Rich_Web_Forms_Upd_Theme_ID').val(Rich_Web_Forms_T_ID);
    jQuery('.Rich_Web_Forms_Content_Data1_Theme').css('display', 'none');
    jQuery('.Rich_Web_Forms_Add_Theme').addClass('Rich_Web_Forms_Add_ThemeAnim');
    jQuery('.Rich_Web_Forms_Content_Data2_Theme').css('display', 'block');
    jQuery('.Rich_Web_Forms_Update_Theme').addClass('Rich_Web_Forms_Save_ThemeAnim');
    jQuery('.Rich_Web_Forms_Cancel_Theme').addClass('Rich_Web_Forms_Cancel_ThemeAnim');
}

function Rich_Web_Forms_Delete_Theme(Rich_Web_Forms_T_ID) {
    var RWFRFT = Rich_Web_Forms_T_ID;
    jQuery('.Rich_Web_Forms_Fixed_Div').fadeIn();
    jQuery('.Rich_Web_Forms_Absolute_Div').fadeIn();

    jQuery('.Rich_Web_Forms_Relative_No').click(function() {
        jQuery('.Rich_Web_Forms_Fixed_Div').fadeOut();
        jQuery('.Rich_Web_Forms_Absolute_Div').fadeOut();
        RWFRFT = null;
    })
    jQuery('.Rich_Web_Forms_Relative_Yes').click(function() {
        if (RWFRFT != null) {
            jQuery('.Rich_Web_Forms_Fixed_Div').fadeOut();
            jQuery('.Rich_Web_Forms_Absolute_Div').fadeOut();
            var ajaxurl = rw_form_json_object.ajaxurl;
            var data = {
                action: 'Rich_Web_Forms_Del_Theme',
                rw_form_nonce_field: rw_form_json_object.rw_forms_nonce,
                foobar: Rich_Web_Forms_T_ID,
            };
            jQuery.post(ajaxurl, data, function(response) {
                if (response.success !== true) {
                    console.error("Not valid nonce.");
                    return false;
                }
                location.reload(true);
            })
        }
        RWFRFT = null;
    })
}

function Rich_Web_Forms_Copy_Theme(Rich_Web_Forms_T_ID) {
    var ajaxurl = rw_form_json_object.ajaxurl;
    var data = {
        action: 'Rich_Web_Forms_Copy_Theme',
        rw_form_nonce_field: rw_form_json_object.rw_forms_nonce,
        foobar: Rich_Web_Forms_T_ID,
    };
    jQuery.post(ajaxurl, data, function(response) {
        if (response.success !== true) {
            console.error("Not valid nonce.");
            return false;
        }
        location.reload(true);
    })
}

function Rich_Web_Forms_RangeSlider() {
    var slider = jQuery('.Rich_Web_Forms_Range'),
        range = jQuery('.Rich_Web_Forms_Range__range'),
        value = jQuery('.Rich_Web_Forms_Range__value');
    slider.each(function() {
        value.each(function() {
            var value = jQuery(this).prev().attr('value');
            jQuery(this).html(value);
        });
        range.on('input', function() {
            jQuery(this).next(value).html(this.value);
        });
    });
}