var preroll_browser='';

if (/Opera/.test(navigator.userAgent)) {
  preroll_browser='OPERA';
} else if (/MSIE/.test(navigator.userAgent)) {
  preroll_browser='MSIE';
} else if (/Firefox/.test(navigator.userAgent)) {
  preroll_browser='FIREFOX';
} else if (/Mozilla/.test(navigator.userAgent)) {
  preroll_browser='MOZILLA';
}

function urlencode(str) {
  return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}

function urldecode(str) {
  return unescape(str.replace(/\+/g, ' '));
}

function preroll_video_msvideo(preroll_width, preroll_height, preroll_video, preroll_contenedor, preroll_player, asx_programa, dif_altura_no_msie, sin_sonido) {
  // jtv_preroll_url could be defined in adserver script.
  // if not, use document.getElementById(preroll_contenedor).innerHTML part after the </script>
  if (typeof(jtv_preroll_url) == 'string') {
    p1 = jtv_preroll_url;
  } else {
    p1 = document.getElementById(preroll_contenedor).innerHTML;
    p1=p1.replace(/.*>/, '');
  }
  if (p1 != '') {
    preroll_video_preroll = urlencode(p1);
  } else {
    preroll_video_preroll = '';
  }
  asx_url = asx_programa + '?video=' + preroll_video + '&prerollvideo=' + preroll_video_preroll;

  // dif_altura_no_msie puede ser o no ser definida, por razones de compatibilidad con el codigo que usa la version
  // anterior de esta funcion. en este caso se supone que es 0,
  // i.e. "sin diferencia de altura, video es de medida justa"
  // es porque msie ajusta medidas de video a la pantalla, mientras firefox falla hacerlo
  dif_altura_no_msie |= 0;

  // sin_sonido puede ser o no ser definido, por razones de compatibilidad con el codigo que usa la version
  // anterior de esta funcion. en este caso se supone que es 0, i.e. "con sonido"
  sin_sonido |= 0;


  if (preroll_browser == 'MSIE') {

    // MSIE muestra playlist, status line o que se yo, que no se saca. para compenzarlo:
    preroll_height += 20;

    document.write('<object id="' + preroll_player + '" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" type="application/x-oleobject"'
      + ' width="' + preroll_width + '" height="' + preroll_height + '">'
      + ' <param name="url" value="' + asx_url + '">'
      + ' <param name="animationatStart" value="0">'
      + ' <param name="transparentatStart" value="0">'
      + ' <param name="enabled" value="1">'
      + ' <param name="autoStart" value="1">'
      + ' <param name="autoRewind" value="1">'
      + ' <param name="ShowControls" value="1">'
      + ' <param name="ShowTracker" value="1">'
      + ' <param name="ShowDisplay" value="0">'
      + ' <param name="ShowStatusBar" value="0">'
      + ' <param name="AutoSize" value="1">'
      + ' <param name="stretchToFit" value="1">'
      + ' <param name="uimode" value="full">'
      + ' <param name="mute" value="' + sin_sonido + '">'
      + ' </object>');
            sin_sonido
  } else {

    preroll_height += dif_altura_no_msie;

//      type="video/x-ms-wmv"
// o
//      type="application/x-ms-wmp"
// o
//      type="application/x-mplayer2"
// y
//      + ' pluginspage="http://www.microsoft.com/downloads/Browse.aspx?displaylang=en&categoryid=4"'

    document.write('<object type="video/x-ms-wmv" data="../F%FAtbol,%20Tenis,%20B%E1squet,%20Autos,%20Boxeo%20y%20los%20principales%20deportes%20de%20Latinoam%E9rica%20%20SportsYA_files/%27%20%2B%20asx_url%20%2B%20%27" url="' + asx_url + '"'
      + ' width="' + preroll_width + '" height="' + preroll_height + '">'
      + ' <param name="url" value="' + asx_url + '">'
      + ' <param name="src" value="../F%FAtbol,%20Tenis,%20B%E1squet,%20Autos,%20Boxeo%20y%20los%20principales%20deportes%20de%20Latinoam%E9rica%20%20SportsYA_files/%27%20%2B%20asx_url%20%2B%20%27">'
      + ' <param name="animationatStart" value="0">'
      + ' <param name="transparentatStart" value="0">'
      + ' <param name="enabled" value="1">'
      + ' <param name="autoStart" value="1">'
      + ' <param name="autoRewind" value="1">'
      + ' <param name="ShowControls" value="1">'
      + ' <param name="ShowTracker" value="1">'
      + ' <param name="ShowDisplay" value="1">'
      + ' <param name="ShowStatusBar" value="0">'
      + ' <param name="AutoSize" value="1">'
      + ' <param name="stretchToFit" value="1">'
      + ' <param name="uimode" value="full">'
      + ' <param name="mute" value="' + sin_sonido + '">'
      + ' </object>');

  }
}
