Existence of extremal functions for a family of Caffarelli-Kohn-Nirenberg inequalities