function loadflash2(params){
  var s = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+params.width+'" height="'+params.height+'">\
<param name="movie" value="'+params.src+'">\
<param name="flashvars" value="'+params.vars+'">\
<param name="allowscriptaccess" value="always">\
<param name="wmode" value="window">\
<embed allowscriptaccess="always" wmode="window" src="'+params.src+'" flashvars="'+params.vars+'" width="'+params.width+'" height="'+params.height+'"></embed>\
</object>';
  var pelem = document.createElement('div');
  pelem.id = params.id;
  document.body.appendChild(pelem);
  with(document.getElementById(params.id)){
    style.position = 'absolute';
    if(!(/MSIE (6|7|8)/.test(navigator.userAgent)))
      style.position = 'fixed';
    style.top = '50%';
    style.left = '50%';
    style.marginLeft = 0 - params.width  / 2 + 'px';
    style.marginTop  = 0 - params.height / 2 + 'px';
    style.backgroundColor = 'white';
    innerHTML = s;
  }
};

function setCookie(c_name, value, expiredays){
  var exdate=new Date();
  exdate.setDate(exdate.getDate() + expiredays);
  document.cookie = c_name + "=" + escape(value) + (expiredays==null ? "" : ";expires="+exdate.toGMTString()+";path=/");
};

function getCookie(c_name){
  if (document.cookie.length>0){
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1){
      c_start=c_start + c_name.length+1;
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
      return unescape(document.cookie.substring(c_start,c_end));
    }
  }
  return false;
};

function closeflash(id){
  setTimeout(function(){
    var sid = document.getElementById(id);
    if(sid) sid.parentNode.removeChild(sid);
  },100);
};

if(getCookie('popuprich_banner') < popuprich.unique ){
  var cCook = getCookie('popuprich_banner');
  cCook?cCook++:(cCook=1);
  if(/MSIE (6|7|8)/.test(navigator.userAgent))
    window.attachEvent('onload',function(){
      loadflash2({
        width: popuprich.width,
        height: popuprich.height,
        src: popuprich.flash,
        vars: 'flink='+popuprich.link+'&param1='+popuprich.link+'&fid='+popuprich.id,
        id: popuprich.id
      });
      var exdate=new Date();
      exdate.setDate(exdate.getDate() + 1);
      document.cookie = 'popuprich_banner='+cCook+';expires='+exdate.toGMTString()+";path=/";
      if(popuprich.time)
        setTimeout(function(){
          closeflash(popuprich.id);
        },popuprich.time * 1000);
    });
  else{
    window.addEventListener('DOMContentLoaded',function(){
      loadflash2({
        width: popuprich.width,
        height: popuprich.height,
        src: popuprich.flash,
        vars: 'flink='+popuprich.link+'&param1='+popuprich.link+'&fid='+popuprich.id,
        id: popuprich.id
      });
      setCookie('popuprich_banner',cCook,1);
    },false);
    if(popuprich.time)
      setTimeout(function(){
        closeflash(popuprich.id);
      },popuprich.time * 1000);
  }
}
