var CookieManager=
{
	setCookie: function (c_name,value,expiredays)
	{
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+(expiredays?(";expires="+exdate.toGMTString()):"")+";path=/;domain=.tut.by";
	},
	getCookie: function (c_name)
	{
		if(document.cookie.length>0)
		{
			var c_start=document.cookie.indexOf(c_name + "=");
			if (c_start!=-1)
			{
				c_start=c_start + c_name.length+1;
				var 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 undefined;
	},
	delCookie: function (name)
	{
		document.cookie = name+'=; expires=Thu, 01-Jan-70 00:00:01 GMT;path=/';
	}
};
function changeIt (obj,sTagName,dY)
{
	var oEls=obj.getElementsByTagName(sTagName);
	if(oEls) try{
		oEls[0].setAttribute("height",dY);
	}catch(e){}
}
function BannerSlotSize(iHeight,sPlaceId)
{
		var oPlace=document.getElementById(sPlaceId);
		if(oPlace)
		{
			var sBannerId=oPlace.getAttribute("xBannerId");
			var iShowCountMax=parseInt(oPlace.getAttribute("xShowCount"),10);
			var iShowCount=parseInt(oPlace.getAttribute("xShowCurrent"),10);
			if(iShowCount<=iShowCountMax)
			{
				changeIt(oPlace,"embed",iHeight);
				changeIt(oPlace,"object",iHeight);
			}
		}
}
function bannerExpandOld(sId)
{
	var eId = document.getElementById(sId);
	if(eId)
	{
		var sBannerId=eId.getAttribute("xBannerId");
		var sCookieName="advExpand"+sBannerId;
		var iExpandCount=CookieManager.getCookie(sCookieName);
		if(iExpandCount)
			iExpandCount = parseInt(iExpandCount,10);
		else
		{
			iExpandCount=1;
		}
		if(iExpandCount <= 2)
		{
			changeIt(eId,"embed",300);
			changeIt(eId,"object",300);
			setTimeout(function()
			{
				changeIt(eId,"embed",60);
				changeIt(eId,"object",60);
			},6700);
			iExpandCount=iExpandCount+1;
			CookieManager.setCookie(sCookieName,iExpandCount,1);
		}
	}
}
var bCounted = false;
function bannerExpand(sId)
{
	var eId = document.getElementById(sId);
	if(eId)
	{
		var sBannerId=eId.getAttribute("xBannerId");
		var sCookieName="advExpand"+sBannerId;
		var iExpandCount=CookieManager.getCookie(sCookieName);
		if(iExpandCount)
		{
			iExpandCount = parseInt(iExpandCount,10);
			if(!bCounted){
				iExpandCount=iExpandCount+1;
				CookieManager.setCookie(sCookieName,iExpandCount,1);
				bCounted = true;
			}
		}else
		{
			iExpandCount=1;
			CookieManager.setCookie(sCookieName,iExpandCount,1);
			bCounted = true;
		}
		if(iExpandCount <= 2)
		{
			changeIt(eId,"embed",300);
			changeIt(eId,"object",300);
			setTimeout(function()
			{
				changeIt(eId,"embed",60);
				changeIt(eId,"object",60);
			},5000);
		}
	}
}
function bannerState(sId,sCommand)
{
	var eId = document.getElementById(sId);
	if(eId)
	{
		if(sCommand == "expand"){
			changeIt(eId,"embed",300);
			changeIt(eId,"object",300);
		}else{
			changeIt(eId,"embed",90);
			changeIt(eId,"object",90);
		}
	}
}
function FillBannerSlot(sPlaceId,iShowCountMax,sBanner)
{
	var sBannerId="xxx";
	var aMatch=sBanner.match(/<embed[^>]*src="([^">]+)"/)
	if(aMatch && aMatch.length>0)
	{
		sBannerId=aMatch[1].replace(/^.*\/([0-9]+)_[^\/]+$/,"$1");
	}
	var sCookieName="advSlider"+sBannerId;
	var iShowCount=CookieManager.getCookie(sCookieName);
	if(iShowCount)
	{
		iShowCount=parseInt(iShowCount,10)+1;
		CookieManager.delCookie(sCookieName);
	}
	else
		iShowCount=1;
	CookieManager.setCookie(sCookieName,iShowCount,7);
	var srso = "1";
	sCookieName="advExpand"+sBannerId;
	var iExpandCount=CookieManager.getCookie(sCookieName);
	if(iExpandCount)
	{
		srso="";
	}
	
	var sAddon="count="+iShowCountMax+"&place="+sPlaceId+"&link1=http:\/\/preved.tut.by\/?clickid="+ sBannerId+"&fname=bannerExpandOld&rso="+srso;
	document.write("<div id=\""+sPlaceId+"\" xBannerId=\""+sBannerId+"\" xShowCount=\""+iShowCountMax+"\" xShowCurrent=\""+iShowCount+"\">");
	document.write(sBanner.replace(/(<object[^>]+)>/,"$1 id=\""+sBannerId+"\"><param name=\"allowScriptAccess\" value=\"always\"><param name=\"flashvars\" value=\""+sAddon+"\">").replace("<embed","<embed allowScriptAccess=\"always\" flashvars=\""+sAddon+"\""));
	document.write("</div>");
}

