function CreateFlash(id, file, width, height, transparent, param) {
  var d = document;

  d.writeln('<object id="' + id + '" data="' + file + '" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '">');
  d.writeln('  <param name="movie" value="' + file + '" />');
  d.writeln('  <param name="menu" value="false" />');
  d.writeln('  <param name="quality" value="best" />');
  d.writeln('  <param name="scale" value="noscale" />');
  if (transparent)
    d.writeln('  <param name="wmode" value="transparent" />');
  if (param != null)
    d.writeln('  <param name="flashvars" value="' + param + '" />');

  d.writeln('</object>');
}


function AvisoLogin() {
  window.alert('É necessário efetuar o login para acessar esta opção.');
}


function GetFlashVersion() {
  var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ?
    navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;

  if (plugin) {
    var desc = navigator.plugins["Shockwave Flash"].description.split(" ");

    for (var i = 0; i < desc.length; i++) {
      if (isNaN(parseInt(desc[i])))
        continue;

      return desc[i];
    }
  }

  if (window.ActiveXObject) {  // ActiveX (IE)
    var strid = 'ShockwaveFlash.ShockwaveFlash.';
    var verid = 15; // versão máxima - 1
    var f;

    while (--verid) {
      try {
        f = new ActiveXObject(strid + parseInt(verid));
        if (f != null)
          return verid;
      } catch (e) {
      }
    }
  }

  var flashVersion = navigator.appName.indexOf("Microsoft") != -1 ? window["flashver"] : document["flashver"];
  var ver;

  if (flashVersion != null) {
    try {
      ver = flashVersion.chkVersion();
      return ver.substring(ver.indexOf(' ') + 1, ver.indexOf(','));
    } catch (e) {
    }
  }

  return 0;
}


function checaBrowser() {
  var fver = GetFlashVersion();

  if (AjaxInstance() == null) {
    document.getElementById('loginwarn_ajax').style.visibility = 'visible';
    document.getElementById('loginwarn_ajax').style.display    = 'block';
  } else if (fver == 0) {
    document.getElementById('loginwarn_noflash').style.visibility = 'visible';
    document.getElementById('loginwarn_noflash').style.display    = 'block';
  } else if (fver < 8) {
    document.getElementById('loginwarn_flashver').style.visibility = 'visible';
    document.getElementById('loginwarn_flashver').style.display    = 'block';
  } else if (!navigator.cookieEnabled) {
    document.getElementById('nocookie').style.visibility = 'visible';
    document.getElementById('nocookie').style.display    = 'block';
  }
}


function testaPopUp() {
  var popup = window.open("about:blank", "_blank", "width=1,height=1,top=10000,left=10000");

  if (!popup || popup.closed)
    return false;

  popup.close();
  return true;
}


function topFixed(control, dist) {
  control.style.top = dist + 'px';

  var ieMatch = navigator.appVersion.match(/MSIE (\d+)\./);

  if (!ieMatch || +ieMatch[1] >= 7) {
    control.style.position = 'fixed';
  } else {
    control.style.position = 'absolute';
    setInterval(function(control) {
      control.style.display = 'none';
      control.style.top = dist + 'px';
      control.style.display = 'block';
    }, 10, control);
  }

  // centro
  // var pos = (document.width / 2) - (control.offsetWidth / 2);
  // direita

  var pos;
  if (document.width)
    pos = document.width - control.offsetWidth - 20;
  else
    pos = document.body.clientWidth - control.offsetWidth - 20;

  control.style.left = pos + 'px';
}


function html_entity_decode(str) {
  var ta = document.createElement("textarea");

  ta.innerHTML = str.replace(/</g,"&lt;").replace(/>/g,"&gt;");

  return ta.value;
}
