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