Ummm...as I read that, you are trying to attach the event listeners to those various forms, WHETHER OR NOT the form exists in that page!
So the first one that doesn't exist (which will indeed addform if you are on the edit page?) you get an error and everything stops.
Maybe a simple answer is to ignore any request to set the listener on a null item?
Code:
function attachEventListener(target, eventType, functionRef, capture)
{
if ( target == null ) { return true; }
if ( target.addEventListener != null )
{
target.addEventListener(eventType, functionRef, capture);
}
else
{
target.attachEvent("on" + eventType, functionRef);
}
return true;
};