Dust formation in the ejecta of the type II-P supernova 2004dj