The most common type of bankruptcy (Chapter 7) stops a foreclosure
(in Alaska, if done before the date of foreclosure sale) but does so
only temporarily.

A second type of bankruptcy (Chapter 13) not only stops the
foreclosure but may provide a method by which you can pay back your
late payments over three to five years. This assumes you have enough
income to keep up with the current payments and to pay some amount
to the court on the back payments.
To see if you qualify, consult
with an attorney well before the foreclosure date.

Don't assume that your lender or mortgage company will rewrite the
loan. If you are more than 2 or 3 months late, chances are the lender
will not work with you. Try the lender first, but do not delay speaking
with a bankruptcy attorney if your efforts are not quickly successful.

                TO AVOID A BANKRUPTCY

Please consult with a bankruptcy attorney before you try this approach!
Let's look at this issue - I have had many, many clients who regret they
took this approach before consulting with me.

1. The home equity loan will involve either rewriting your existing
mortgage at a much higher interest rate or will involve a second
mortgage at a very, very high interest rate.

2. A home equity loan is not eliminated in a bankruptcy. If you are
unable to pay all of your debts and are forced to file a bankruptcy in the
future, you will owe on either the higher interest rate mortgage or on
both mortgages (if you received a second mortgage rather than a
rewritten first mortgage). In either event, this debt is not eliminated. Of
course, you can surrender your house and file that
case, you will no longer be responsible personally for the home equity
loan -
but you have traded your home for consumer debt!  
Likewise, do not borrow from retirement accounts without
careful consideration first.

Do not threaten these assets because you are afraid of a bankruptcy
or bad credit. Consult an attorney first.

                    LOAN MODIFICATIONS

A loan modification is a government-sponsored program to make your
mortgage payments more affordable.  This is something you can look
into whether or not you file a bankruptcy.  Here's a link to the
government website on loan modifications:

Loan Modification Programs