Can Muslims Enter a Church or Synagogue?

Traveling around the world often involves visiting local religious buildings. Among them are non-Muslim religious temples. Can a Muslim visit a church or synagogue in such cases? Or, if necessary, perform namaz there?