Download and Run Tinyumbrella:
1) Make sure you Iphone is detected.
2) check "Advanced Options."
3) In new window, under "Device / Version," select 3.1.3 firmware.
4) Click on "Save my SHSH." Pray Cydia has them. If you don't get an error, the SHSH hash has was saved onto your computer.
5) Repeat to save other firmware hashes if you want.
6) Now, click on "Display SHSHs." It should listed all hashes you have saved onto your computer.
7) Click on "TSS server."
8) Download firmware (google) you can restore in #6.
9) In ITunes, restore using firmware you just downloaded.
10) If phone get stuck during restore, try "Kick out of recovery..." in Tinyumbrella.
Edit: 3.1.3 JB are Spirit or Jailbreakme.com. They are userland JB which means they will not activate the phone. You will need an official carrier sim card to activate the phone or else you will be stuck with emergency call only.