Fixed errors.

30: made i local instead of global.
31: added check to make sure window is a browser window

36-37: made second loop use i2 instead of i to avoid collision.

74: fixed name typo.