Attachment Maintance Querys to subs

Some attachment maintenance querys moved to subs.  I did change around a bit how that all worked as it seemed to be, for me, hard to follow what it was trying to do with some of the session vars etc ... Tried to simply things.  Maybe someone knows why it was doing it the way it was.

Also added the attachment maintenance as an option to maintenance, its still in its old location as well.