var tmp=get_parametr('code').split(',');
document.write('<div style="position: relative; border: none; width: '+tmp[1]+'px; height: '+tmp[2]+'px; padding: 0px; margin: 0px;">');
document.write('<iframe style="border: none; width: '+tmp[1]+'px; height: '+tmp[2]+'px; padding: 0px; margin: 0px;" frameborder="0px" border="0px" scrolling="no" src="http://reklama2.egrupa.pl/show_box.php?code='+tmp[0]+'"></iframe>');
document.write('<div style="position: absolute; top: '+(tmp[2]-20)+'px; right: 0px; text-align: right;"><a href="#" style="padding-right: 10px;" title="Dodaj reklame" onclick="javascript: ad_egrupa.open(\''+tmp[0]+'\'); return false;">Dodaj reklame</a></div>');
document.write('</div>');

function get_parametr(param)
{
  var scriptElement = document.getElementsByTagName("script");
  scriptElement = scriptElement[scriptElement.length-1];
  var query = scriptElement.getAttribute('src').substring(1);
  query=query.split('?')[1];
  var parms = query.split('&');
  for (var i=0; i<parms.length; i++)
  {
    var pos = parms[i].indexOf('=');
    if (pos > 0)
    {
      var key = parms[i].substring(0,pos).toLowerCase();
      var val = parms[i].substring(pos+1);
      if(key == param.toLowerCase()) { return val; }
    }
  }
  return null;
}
function addCss(path)
{
	var link = document.createElement("link");
	setAttribute(link, "rel", "stylesheet");
	setAttribute(link, "type", "text/css");
	setAttribute(link, "href", path);
	var heads = document.getElementsByTagName("head");
	for(var i=0;i<heads.length;i++) { heads[i].appendChild(link); }
}
function setAttribute(node, attr, value)
{
	if(value == null || node == null || attr == null) return;
	if(attr.toLowerCase() == "style")
	{ setStyleAttribute(node, value); }
	else { node.setAttribute(attr, value); }
}

ad_egrupa = {
	open : function(code)
	{
		var w=840;
		var h=600;
		//iframe
		var lay=document.createElement('iframe');
		//umieszczenie reklamy na środku
		var win=this.get_window_size();
		lay.style.position="fixed";
		lay.style.left=((win[0]-w)/2)+"px";
		lay.style.top=((win[1]-h)/2)+"px";
		//zmiana rozmiaru reklamy
		lay.style.zIndex=499;
		lay.style.width=w+'px';
		lay.style.height=h+'px';
		lay.style.backgroundColor="#F0F0F1";
		//pozostałe
		lay.style.border="1px solid red";
		lay.style.margin="0px";
		lay.style.padding="0px";
		lay.src="http://reklama2.egrupa.pl/web_gen/"+code+"/";
		lay.id="code_"+code;
		//przycisk zamknięcia
		var div=document.createElement('div');
		div.style.position="fixed";
		div.style.left=((win[0]-w)/2-15)+"px";
		div.style.top="15px";
		div.style.zIndex=500;
		div.style.width=w+'px';
		div.style.height='20px';
		div.style.textAlign="left";
		div.id="coded_"+code;
		div.innerHTML="<img src='http://wszystkieprojekty.pl/images/layout/zamknij.png>";
		div.onclick=function() { ad_egrupa.close(code); };
		
		document.getElementsByTagName("body")[0].appendChild(lay);
		document.getElementsByTagName("body")[0].appendChild(div);
	},
	
	close : function(code)
	{
		document.getElementsByTagName("body")[0].removeChild(document.getElementById("code_"+code));
		document.getElementsByTagName("body")[0].removeChild(document.getElementById("coded_"+code));
	},
	
	get_window_size : function()
	{
		var d=document;
		var w=window;
		if (typeof w.innerWidth!='undefined')
		{ var winWidth = w.innerWidth; var winHeight = w.innerHeight; }
		else
		{
			if (d.documentElement && typeof d.documentElement.clientWidth!='undefined' && d.documentElement.clientWidth!=0)
			{ var winWidth = d.documentElement.clientWidth; var winHeight = d.documentElement.clientHeight; }
			else
			{
				if (d.body && typeof d.body.clientWidth!='undefined')
				{ var winWidth = d.body.clientWidth; var winHeight = d.body.clientHeight; }
			}
		}
		return new Array(winWidth, winHeight);
	}
};
