(function() {
    fitbit.namespace("fitbit.app.user.profile.privacy");
    fitbit.app.user.profile.privacy = {
        onCheckboxClick: function(checkboxId, valueChecked, valueUnchecked) {
            var checkbox = Y.Dom.get(checkboxId);
            checkbox.value = checkbox.checked ? valueChecked : valueUnchecked;
            // A value does not get submitted for a checkbox which is not checked. Our implementation of the dialog
            // action bean requires having a privacy level value for each target submitted. Here is how we guarantee
            // that a value gets submitted for the checkbox whether it is checked or not:
            //
            // Maintain a shadow checkbox with the same name and value as the checkbox, but opposite checked status.
            // If the main checkbox is unchecked (checked is false), nothing will be submitted for it. The shadow
            // checkbox will have checked set to true, and it will be submitted with the same name.
            var checkboxShadow = Y.Dom.get(checkboxId + '.shadow');
            checkboxShadow.checked = !checkbox.checked;
            checkboxShadow.value = checkbox.value;
        }
    };
})();

