What's probably going on when you are connected to Internet is that your system tries to resolve name
localhost in yours ISP DNS servers.
As a solution you can define name
localhost as IP address
127.0.0.1 in your hosts file which is read before querying DNS servers. Since you have Windows 7 you should have required entry in
C:\Windows\System32\drivers\etc\hosts file but by default it's commented out. Start Notepad as Administrator by right-clicking on it and choosing
Run as Administrator. Open your hosts file and change lines:
# 127.0.0.1 localhost
# ::1 localhost
Basically uncomment it by removing
# from the beginning of these two lines. Save the file and test if it resolved your problem.