Warning: This will erase ALL data on your phone (although not memory card)
There are two ways to restore your phone to it's factory settings:
If your phone is working fine, then go to Menu - Settings - Phone - Phone management - Factory settings - Delete data and restore
If your phone has frozen, then hold down the power button for 8 seconds. This should turn the phone off. Try turning it on normally again to see if that solves the problem you are having. If not, then to hard reset it, hold down the Volume down + Camera key + Menu key. Then while holding them down, hold the Power button. The phone will then shake to indicate it's rebooting.