The very first thing you should do, and please do it asap... is go see a Bankruptcy attorney. Most offer a free consultation and can advise you as to which chapter you qualify for and what would be best in your situation.
As far as the mortgages and how much you may be held responsible for after foreclosure.. that will depend entirely upon how much the home is sold for after the foreclosure. Typically they are sold to the highest bidder, often for less than fair market value. So depending upon the market in your area and the value of your home, you could be left owing very little, or all of the 2nd mortgage, and maybe even some of the 1st. Again it depends on how much the house is sold for.
Unfortunately the information you provided is not enough for anyone to tell you on this forum which chapter would be best for you. This is why you should see an attorney ASAP. He/she will review every aspect of your situation and determine what you qualify for.
Good luck!!

