How can I tell if an external window is maximized? Also, if it is maximized, I want to restore it so that its not maximized (the equivilant of clicking the middle button on the window).

Any ideas?
Jordan