Those kinds of thoughts are called obsessive-compulsive.
I know the name doesn't seem to fit, but that's what it's called.
It's caused from anxiety. People who have them feel frightened
by bad thoughts, but never actually do them. It's a way for your
mind to release its anxiety, and it certainly does make you feel
alarmed and upset. Don't give up. You will get through this.
You are not a bad person. Go to see a doctor who can prescribe
an anti-depressant, like paxil, zoloft, celexa, prozac. They are
all a certain class of anti-depressants that will greatly help you
with anxiety. They are non-addictive medications.