forEach (not supported by IE8) replaced with for loop

forEach() javascript method (not supported by IE8 and older: http://j.mp/1t8vsfR) replaced with a simple for loop (supported by all browsers).