A general framework for implementing NLO calculations in shower Monte Carlo programs: the POWHEG BOX