validate doc_type before wrapping

http://manage.dimagi.com/default.asp?142908