Cognitive behavioral therapy is one of the safest, most helpful treatments for changing thought patterns and behaviors. Here's how it works.