Update: Newer post;
Factory Reset iPhone 3G
Now that most of you got the new iPhone 3GS, you might be thinking of giving away or selling your iPhone 3G. But you may want make sure that you completely erase and set the iPhone to original factory condition. Just resetting the does not erase everything and you might end up giving away very valuable information.
Completely resetting the iPhone takes a while and you need assign about one hour for the procedure and you need to have the iPhone plugged into a power source through the procedure. Since I have written this procedure before with screen captures and instructions for every step, I am going to point you to that article.
Enjoy your new iPhone 3GS and give away or sell your old phone without any worry.
Reset Your iPhone To Factory Setting. (Low Level Format Your iPhone) | VOIP IP Telephony