check if it's a string before trying to do a replace on it

this was throwing an error for me in IE 8 and adding this check fixed it.