
function hasFlash(version) {
  version = (version != null ? version : 8);
  return getFlashVersion() >= version;
}


function getFlashVersion() {
  return _flash;
}

function getCookie(name) {
  var cookie = '' + document.cookie;
  var i = cookie.indexOf(name), j = cookie.indexOf(';', i + 1);
  if (i != -1) {
    if (j == -1) { j = cookie.length; }
    return unescape(cookie.substring(i + name.length + 1, j));
  }
  return '';
}

function setSessionCookie(name, value) {
  document.cookie = name + '=' + escape(value) + ';domain=' + parseDomain() +
    ';path=/';
}

function parseDomain(hostname) {
  if (!hostname) { hostname = '' + location.hostname; }
  var i = hostname.lastIndexOf('.');
  if (i > 0) {
     i = hostname.lastIndexOf('.', i - 1);
     return hostname.substring(i + 1);
  }
  return '';
}

var _flash = parseInt(getCookie('flash'));
if (isNaN(_flash)) {
  var flash = 0, x;
  if (navigator.mimeTypes) {
    x = navigator.mimeTypes["application/x-shockwave-flash"];
    if (x && x.enabledPlugin) {
      x = x.enabledPlugin.description;
      if (x != null) {
        flash = parseInt(x.substring(x.indexOf('.') - 1));
      }
    }
  }
  if (!flash) {
    x = navigator.userAgent;
    if (x && x.indexOf("MSIE") >= 0 && x.indexOf("Win") >= 0) {
      x=document.writeln;
      x('<scr'+'ipt language="VBScript">');
      x('on error resume next');
      x('private i, j');
      x('for i = 9 to 1 step -1');
      x('set j=CreateObject("ShockwaveFlash.ShockwaveFlash." & i)');
      x('if IsObject(j) then');
      x('flash = i');
      x('exit for');
      x('end if');
      x('next');
      x('</scr'+'ipt>');
    }
  }
  _flash = isNaN(flash) ? 0 : flash;
  setSessionCookie('flash', _flash);
}

