Fixed Bugs in IE8 caused by using document.head and trim()

IE8 doesn't know ```document.head``` as well as ```trim()``` which causes an Javascript error. Fixed by alternatively using ```document.getElementsByTagName("head")[0]``` and ensuring that ```trim()``` is a function.