events function added with error on attachEvent