/**
 * Fixes the problem that the YouTube iframe embed code displays nothing if the
 * video title contains non-ascii characters and the browser fails to detect the
 * encoding. YouTube does not provide the charset by either the HTTP response
 * header or meta tag, as of 2011-02-17.
 */
function fixYouTubeIFrames()
{
  var filter = 'http://www.youtube.com/';
  var iframes = document.getElementsByTagName('iframe');
  for (var i = 0; i < iframes.length; ++i)
  {
    var src = iframes[i].getAttribute('src');
    if (filter == src.substr(0, filter.length).toLowerCase())
    {
      // Adds attributes for hinting, though they are not valid HTML.
      iframes[i].setAttribute('charset', 'UTF-8');
      iframes[i].setAttribute('type', 'text/html; charset=UTF-8');
      // Reloads the iframe.
      iframes[i].setAttribute('src', src);
    }
  }
}

window.onload = function()
{
  fixYouTubeIFrames();
}

