I've been searching for a few days (both the forums and through code) for this answer but I can't seem to find it, hope someone can help me out.

site is setup for must login to view prices
If a customer logs in from any page other than a product page, so a category, sub category or the main page of the site, AND they have previous orders from the site - they are directed to their Account page.
I want to change this so that when they login from any page Other than a product page, they are redirected to either
a)the main site page
or
b)the page they were viewing when they decided to login
whichever is easier :)

Thanks for your time