I don't think it's illegal, at least here in California; however, it *is* against Visa/MC's merchant policies. Think about it: if the merchants all charged surcharges for credit cards, consumers would be that much more motivated not to use the credit cards for purchases. That's obviously not in the credit card companies' best interests, particularly if you notice all the incentives (air miles, rebates, etc.) they throw our way to use them for just about everything.
"Cash Discount" is a semantic workaround.
Some states and countries, however, have laws that prevent enforcement of the no-surcharge policy, so you'll see this vary by region.
Losing money? The only time a sale is losing money is when the product is sold for less than cost.
Accepting credit cards allows for an increase in revenues thanks to sales which would not have occurred otherwise. That's *additional revenue*. The surcharge is simply expensed as cost-of-sales, a nicely predictable cost at that. And most successful retail merchants with whom I've interacted have seamlessly accounted for this cost of sale within their pricing model, making it imperceptible to (and rather convenient with regard to payment options for) the consumer.
And anyone paying 3-5% for credit card transactions is getting fucked. Costco resells Nova merchant services for 1.67% + $.20 per transaction for card-present transactions: a pittance compared to other marketing and sales costs.