  function pluginDetected() {
    if ( browser == 1 ) { 
      document.writeln('<SCRIPT LANGUAGE="VBScript"\>');
      document.writeln('on error resume next');
      document.writeln('ipix1 = IsObject(CreateObject("IPIX.Viewers.5"))');
      document.writeln('ipix2 = IsObject(CreateObject("IPIX.ActiveXCtrl.2"))');
      document.writeln('ipix3 = IsObject(CreateObject("IPIX.ActiveXCtrl.5"))');
      document.writeln('If ipix1 = True or ipix2 = True or ipix3 = True Then');
      document.writeln('ipixmode = 1');
      document.writeln('Else');
      document.writeln('ipixmode = 0');
      document.writeln('End if');
      document.writeln('</SCRIPT\>');
      return ipixmode;
    } else if ( browser == 2 ) { 
      navigator.plugins.refresh(true);
      numPlugins = navigator.plugins.length;
      if (numPlugins > 0) {
        for (k = 0; k < numPlugins; k++) {
          plugin = navigator.plugins[k];
          if (plugin.description.indexOf("IPIX") != -1) {
            numTypes = plugin.length;
            for (j = 0; j < numTypes; j++) {
              mimetype = plugin[j];
              if (mimetype)       {
                if (mimetype.enabledPlugin && (mimetype.suffixes.indexOf("ipx") != -1)) {
                  return 1;
                }
              }
            }
          }
        }
      }
      return 0;
    }
  }

  function putIPX(fname,width,height){
    if ( browser == 1 ) { 
      document.writeln('      <object id="IpixX1" width="' + width + '" height="' + height + '"');
      document.writeln('        classid="clsid:11260943-421B-11D0-8EAC-0000C07D88CF"');
      document.writeln('        codebase="ipixx.cab#version=6,2,0,5" name="ipix" vspace="0" hspace="0"');
      document.writeln('        border="0">');
      document.writeln('        <param name="_Version" value="65536">');
      document.writeln('        <param name="_ExtentX" value="11924">');
      document.writeln('        <param name="_ExtentY" value="9278">');
      document.writeln('        <param name="_StockProps" value="0">');
      document.writeln('        <param name="IPXFILENAME" value="' + fname +'">');
      document.writeln('      </object>');
    } else if ( browser == 2 ) { 
      document.writeln('      <embed src="' + fname + '"');
      document.writeln('        width="' + width + '" height="' + height + '" palette="FOREGROUND"');
      document.writeln('        type="application/x-ipix"');
      document.writeln('        pluginspage="http://www.ipix.com/cgi-bin/download.cgi"');
      document.writeln('        name="ipix" vspace="0" hspace="0" border="0"');
      document.writeln('        _version="65536" _extentx="11924" _extenty="9278"');
      document.writeln('        _stockprops="0" ipxfilename="' + fname + '">');
      document.writeln('      </embed>');
    }
  }

  function putJava(fname,width,height){
    document.writeln('      <applet archive="IpixViewer.jar" name="IpixViewer" code="IpixViewer.class"');
    document.writeln('        width="' + width + '" height="' + height + '" vspace="0" hspace="0">');
    document.writeln('        <param name="URL" value="' + fname + '">');
    document.writeln('        <param name="SpinSpeed" value="5">');
    document.writeln('        <param name="SpinStyle" value="flat">');
    document.write('      </applet><br>');
  }

  function putError(message,width,height) {
    document.writeln('        <table width="'+width+'" cellpadding=0 cellspacing=0 border=0><tr>');
    document.writeln('        <td><img src="img/empty.gif" width=1 height='+height+'></td>');
    document.writeln('        <td><b>Ошибка:</b>' + message + '</b></td>');
    document.writeln('        </tr></table>');
  }

  function putipx(fname,width,height) {
    browser=0;
    retval = -1;
    fname="ipix/"+fname;
    if ( document.all ) browser=1; else if ( document.layers ) browser=2;
    if ( browser>0 ) {
      if ( pluginDetected() ) {
        putIPX(fname+".ips",width,height);
        retval = 0;
      } else if ( navigator.javaEnabled() ) {
        putJava(fname+".ipx",width,height);
        retval = 1;
      } else  {
        putIPX(fname+".ips",width,height);
        retval = 2;
      }
    } else {
      putError("Не удалось определить тип броузера",width,height);
    }
  }
