pure javascript character encoding conversion