written for http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_21996714.html check the discussion for more details