A 401(k) plan does not have to offer hardship withdrawals at all. If it does offer hardship withdrawals, there are several different choices for how to offer hardships. Ask for a Summary Plan Description or ask to see the official plan document to find the rules for your employer's plan.
Most plans offer hardship withdrawals for the pre-tax deferrals you contributed to the plan. It sounds like your plan probably allows hardship withdrawals if you have one of four safe harbor events listed in the regulation. If you go to
http://frwebgate.access.gpo.gov/cgi-bin/ge...=2000&TYPE=TEXT and search for the word "foreclosure" you'll find the list of 4 events that probably allow you to get a hardship withdrawal.
Note that you'll pay income taxes and a 10% excise tax for early distributions, so you probably only want to tap into your 401(k) for financial emergencies. If you still want a hardship withdrawal, talk to your mortgage lender about receiving a notice that does threaten foreclosure because being in danger of having a car repossessed isn't one of the 4 safe harbor events.