This code originally from a large patch from Rob Browning. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1647 57a11ea4-9604-0410-9ed3-97b8803252fd