// Se escribe el código VBScript necesario para MSIE Windows
var WM_startTagFix = '</';
var msie_windows = 0;
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)){
  msie_windows = 1;
  document.writeln('<script language="VBscript">');
  document.writeln('\'Se buscan los plugins para todas las versiones de Internet Explorer que tengan el motor VBscript versión 2 o mayor.');
  document.writeln('\'Esto incluye todas las versiones de IE4 o superior y algunas versiones de IE 3.');
  document.writeln('Dim WM_detect_through_vb');
  document.writeln('WM_detect_through_vb = 0');
  document.writeln('If ScriptEngineMajorVersion >= 2 then');
  document.writeln('  WM_detect_through_vb = 1');
  document.writeln('End If');
  document.writeln('Function WM_activeXDetect(activeXname)');
  document.writeln('  on error resume next');
  document.writeln('  If ScriptEngineMajorVersion >= 2 then');
  document.writeln('     WM_activeXDetect = False');
  document.writeln('     WM_activeXDetect = IsObject(CreateObject(activeXname))');
  document.writeln('     If (err) then');
  document.writeln('        WM_activeXDetect = False');
  document.writeln('     End If');
  document.writeln('   Else');
  document.writeln('     WM_activeXDetect = False');
  document.writeln('   End If');
  document.writeln('End Function');
  document.writeln(WM_startTagFix+'script>');
}
function WM_pluginDetect(plugindescription, pluginxtension, pluginmime, activeXname){
  // Acá se revisan todos los browsers que tengan un arreglo de plugins
  // (por ejemplo Netscape) y se setean las variables, si no, se redirecciona a la
  // función WM_activeXDetect para detectar el control activeX correspondiente.
  
  // Primero se definen algunas variables
  var i,plugin_undetectable=0,detected=0, daPlugin=new Object();
  // Luego se revisa si es un browser MSIE que permita chequear
  // por el plugin que se está buscando
  if (msie_windows && WM_detect_through_vb){
      plugin_undetectable = 0;
  } else {
      plugin_undetectable = 1;
  }
  // Si tiene un arreglo de plugins o de mimetypes, buscamos primero el plugin
  if(navigator.plugins) {
      numPlugins = navigator.plugins.length;
      if (numPlugins > 1) {
	  if (navigator.mimeTypes && navigator.mimeTypes[pluginmime] && navigator.mimeTypes[pluginmime].enabledPlugin && (navigator.mimeTypes[pluginmime].suffixes.indexOf(pluginxtension) != -1)) {
	      if ((navigator.appName == 'Netscape') && (navigator.appVersion.indexOf('4.0') != -1)) {
		  for(i in navigator.plugins) {
		      if ((navigator.plugins[i].description.indexOf(plugindescription) != -1) || (i.indexOf(plugindescription) != -1)) {
			  detected=1;
			  break;
		      }
		  }
	      } else {
		  for (i = 0; i < numPlugins; i++) {
		      daPlugin = navigator.plugins[i];
		      if ((daPlugin.description.indexOf(plugindescription) != -1) || (daPlugin.name.indexOf(plugindescription) != -1)) {
			  detected=1;
			  break;
		      }
		  }
	      }
      if (navigator.mimeTypes[pluginmime] == null) {
		  detected = 0;
	      }
	  }
	  return detected;
      } else if((msie_windows == 1) && !plugin_undetectable){
	  return WM_activeXDetect(activeXname);
      } else { 		
	  return 0;
      }
  } else {
      return 0;
  }
}
function WM_easyDetect(whichPlugin) {
    var isItThere = 0;
    if( (whichPlugin == 'flash') || (whichPlugin == 'Flash') ) {
	isItThere = WM_pluginDetect('Flash', 'swf', 'application/x-shockwave-flash', 'ShockwaveFlash.ShockwaveFlash');
    } else if( (whichPlugin == 'director') || (whichPlugin == 'Director') ) {
	isItThere = WM_pluginDetect('Shockwave', 'dcr', 'application/x-director', 'SWCtl.SWCtl.1');
    } else if( (whichPlugin == 'quicktime') || (whichPlugin == 'Quicktime') || (whichPlugin == 'QuickTime') ) {
	isItThere = WM_pluginDetect('QuickTime', 'mov', 'video/quicktime', '');
    } else if( (whichPlugin == 'realaudio') || (whichPlugin == 'Realaudio') || (whichPlugin == 'RealAudio') ) {
	isItThere = (WM_pluginDetect('RealPlayer', 'rpm', 'audio/x-pn-realaudio-plugin', 'RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)')) || (WM_pluginDetect('RealPlayer', 'rpm', 'audio/x-pn-realaudio-plugin','rmocx.RealPlayer G2 Control')) || (WM_pluginDetect('RealPlayer', 'rpm', 'audio/x-pn-realaudio-plugin','RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)')) || (WM_pluginDetect('RealPlayer', 'rpm', 'audio/x-pn-realaudio-plugin','RealVideo.RealVideo(tm) ActiveX Control (32-bit)'))
    } else {
	//alert('Debe especificar un plugin válido.');
    }
    return isItThere;
}
function consolaRealPlayer(url, width, height, estilo, imgSinVideo, imgSinSenal, imgSinVideoWidth, imgSinVideoHeight, transmitir) {
	var hasRealPlayer = WM_easyDetect('realaudio');
	if(hasRealPlayer) {
		if (transmitir!="NO") {
    		height2 = height / 8;
    		document.writeln('<table width="' + width + '" height="' + height + '" border="0" align="center" cellpadding="0" cellspacing="0">');
            if (transmitir!="Sólo Audio") {
        		document.writeln('<tr>');
        		document.writeln('	<td width="' + width + '" height="' + height + '"><object id="video1" border="0" width="' + width + '" height="' + height + '">');
        		document.writeln('		<param name="controls" value="ImageWindow">');
        		document.writeln('		<param name="console" value="en_vivo">');
        		document.writeln('		<param name="autostart" value="true">');
        		document.writeln('		<param name="src" value="' + url + '">');
        		document.writeln('		<embed SRC="' + url + '" align="baseline" border="0" width="' + width + '" height="' + height + '" type="audio/x-pn-realaudio-plugin" console="en_vivo" controls="ImageWindow" autostart="true">');
        		document.writeln('		</embed>');
        		document.writeln('		</object></td>');
        		document.writeln('</tr>');
            } else {
                document.writeln('<tr><td><img src="'+imgSinVideo+'" width="'+imgSinVideoWidth+'" height="'+imgSinVideoHeight+'" border="0" alt="" /></td></tr>');
            }
    		document.writeln('<tr>');
    		document.writeln('	<td width="' + width + '" height="' + height2 + '"><object id="video1" align="baseline" border="0" width="' + width + '" height="' + height2 + '">');
    		document.writeln('		<param name="controls" value="CONTROLPANEL">');
    		document.writeln('		<param name="console" value="en_vivo">');
    		document.writeln('		<EMBED NAME="controls" TYPE="audio/x-pn-realaudio-plugin" WIDTH="' + width + '" HEIGHT="' + height2 + '" CONTROLS="CONTROLPANEL"  AUTOSTART="true" CONSOLE="en_vivo">');
    		document.writeln('		</object></td>');
    		document.writeln('</tr>');
    		document.writeln('</table>');
        } else {
            document.writeln('<img src="'+imgSinSenal+'" width="'+imgSinVideoWidth+'" height="'+imgSinVideoHeight+'" border="0" alt="" />');
        }
	} else {
		document.writeln('<table width="' + width + '" height="' + height + '" border="0" align="center" cellpadding="0" cellspacing="0">');
		document.writeln('<tr>');
		document.writeln('	<td width="' + width + '" height="' + height + '" align="center" class="' + estilo + '">Necesitas tener instalado RealPlayer&reg; para ver este contenido, bájalo aquí:<br><DIV ALIGN=CENTER><A HREF="http://www.real.com/player/index.html?lang=es" target="_blank"><IMG SRC="http://www.canal13.cl/portal/art2005/logo_realplayer.gif" BORDER="0" ALT="Descargar RealPlayer gratuito" VSPACE="7"></A></DIV></td>');
		document.writeln('</tr>');
		document.writeln('</table>');
	}
}

