Quandle Rings, Idempotents and Cocycle Invariants of Knots