Variable Javascript String Substring Function