If you file chapter 13 before the mortgage company completes the foreclosure sale then you can keep the house. as soon as your petition is filed, foreclosure stops. It allows for you to bring you payments up to date with in a reasonable abount of time.
here is all the information :
http://www.uscourts.gov/bankruptcycourts/bankruptcybasics/chapter13.ht ml

