The tax consequences of a foreclosure can be complicated, and will ultimately depend on what the mortgage company is able to sell your home for. If the mortgage company sells your home for less than the current mortgage balance, then you may be subject to income tax on the portion of the debt that they end up cancelling.
As far as the second mortgage, you would still be responsible for paying whatever additional debt was owed. If the sale from the home brought in more money than was owed on the first mortgage, the court would then pay the second mortgage with the additional proceeds, but if it were not paid in full, you are still responsible for the debt.
If there is any way possible for you to pay enough off on your mortgage to get your home out of foreclosure, it will definitely be in your best interest.
If this answer has been helpful, please press the "Accept" button. Positive feedback is also greatly appreciated. Thanks for the question and good luck in getting this worked out.