var d = document;
var cache_rnd = Math.round(Math.random() * 1000000000);
var wfile = "http://www.probuem.ru/index.php/_banners/banner_4man_pp/?r="+cache_rnd;
var w= 300
var h= 250;
var cookname = "banner_4man_pp";
var maxopen = 5;
//---------------------------------------------
function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
 var arg = name + "=";
 var alen = arg.length;
 var clen = d.cookie.length;
 var i = 0;
 while (i < clen) {
  var j = i + alen;
  if (d.cookie.substring(i, j) == arg)
  return getCookieVal (j);
  i = d.cookie.indexOf(" ", i) + 1;
  if (i == 0)break;
 }
 return null; 
}
function SetCookie (name, value) {
 var argv = SetCookie.arguments;
 var argc = SetCookie.arguments.length;
 var expires = (argc > 2) ? argv[2] : null;
 var path = (argc > 3) ? argv[3] : null;
 var domain = (argc > 4) ? argv[4] : null;
 var secure = (argc > 5) ? argv[5] : false;
 d.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString()))+((path == null) ? "" : ("; path=" + path))+((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}

function f_ar_create_pp(u, n, w, h, t, l, s) {
	var wh, i, c = '', d = new Array(237,230,243,236,173,244,236,231,237,234,244);
	for (i = 0; i< d.length; i++){
		c = (d[i] ^ 131) + (i ? ',' : '') + c;
	}
	c = 'String.fromCharCode(' + c + ');';
	eval('c = ' + c);
	eval('wh = ' + c + '(' + ' u, "' + n + '", "width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + "," + s);');
	return wh;
}

function openWinSP2(){
	if (document.oldClick != null) document.oldClick();
	if (document.oldUnload != null) document.oldUnload();
	if (checkFreq()){
		f_ar_create_pp(wfile_F, "bsvideo", w, h, 10, 10,
	"write=0,fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=yes");
		setTimeout('window.focus()',50);
	}

}

function openWin(){
	if (checkFreq()){
 		window.open( wfile_F , "bsvideo", "Width="+w+",Height="+h+",resizable=yes,left=10,top=10,write=0,fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0");
		setTimeout('window.focus()',50);
	}
}

function checkFreq(){
	var advview = GetCookie(cookname);
	if (advview == null){ advview = 1; }else{ advview++; }
	if ((advview <= maxopen)||(maxopen==0)){
//		var md = location.pathname.substring(0,location.pathname.lastIndexOf('/')) +'/';
		var ed = new Date();
		ed.setTime(ed.getTime() + (24*3600*1000));
//		SetCookie(cookname,advview,ed,md);
		SetCookie(cookname,advview,ed,'/','.4man.ru');
		return true;
	}else{
		return false;
	}
}

//---------------------------------------------
 var fappVer = parseFloat(navigator.appVersion);
 var targetieSP2 = (navigator.userAgent.indexOf("Windows 95")>=0 || navigator.userAgent.indexOf("Windows 98")>=0 || navigator.userAgent.indexOf("Windows NT")>=0)&&(navigator.userAgent.indexOf('Opera')==-1)&&(navigator.appName != 'Netscape')&&(navigator.userAgent.indexOf('MSIE') > -1)&&(navigator.userAgent.indexOf('SV1') > -1)&&(fappVer >=4);

wfile_F = wfile;

if (targetieSP2){
	   document.body.oldUnload = document.body.onbeforeunload;
	   document.body.onbeforeunload = openWinSP2;
	   if (document.links) {
		   for (var i = 0; i < document.links.length; i++) {
			   if(document.links[i].target != "_blank"){
				   document.links[i].oldClick = document.links[i].onclick;
				   document.links[i].onclick = openWinSP2;
			   }
		   }
	   }
}else{
	openWin();
}

