var imnewmsg = 0;
function OpenIMChat(login,second){
	var urll = "/a-iminit/"+(login? ("ulogin-"+login+"/") : "");//+"<*SESSION>";
	var wnd = window.open("","imwindow",
	"width=1030,height=620,toolbar=no,location=no,menubar=no,resizable=yes");
	
	try{
		if(!wnd.imchat){
			wnd.document.location.href = urll;
		}else{
			wnd.imchat.fChtNewContact(login);
		}
	}catch(e){ wnd.close(); if(!second) OpenIMChat(login,true);}
}

function SetIMMsg(n){
	imnewmsg = n;
	var el1 = document.getElementById("immessage_n");
	var el2 = document.getElementById("immessage");
	if(el1) el1.innerHTML = n? n : '0';
	if(el2) el2.className = n? 'messagenew' : 'message';
}

function OpenIMMsg(ischat){
	if(imnewmsg){
		imnewmsg--;
		if(ischat) fw.chat.fChtNewContact();
		else OpenIMChat();
	}
}

function createFlashBox(url, width, height){
	/* If flashbox exist, remove it */
	if(document.getElementById("flashbox") != null){
		var body = document.getElementsByTagName("body")[0];
		var flashbox = document.getElementById("flashbox");
		body.removeChild(flashbox);
	}

	var div = document.createElement("div"), w = 0, h = 0;
	if(typeof(window.innerWidth) == "number"){
		w = window.innerWidth;
		h = window.innerHeight;
	}else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	}
	div.id = "flashbox";
	div.style.width = width + "px";
	div.style.height = height + "px";
	div.style.left = (w-width)/2 + "px";
	div.style.top = (h-height)/2 + "px";
	div.style.display = "block";

	var rezult = document.createElement("div");
	rezult.className = "rezult";

	var close = document.createElement("div");
	close.className = "close";
	close.title = "Закрыть";
	close.onclick = function(){
		var body = document.getElementsByTagName("body")[0];
		var flashbox = document.getElementById("flashbox");
		body.removeChild(flashbox);
	}
	rezult.appendChild(close);

	var flash = document.createElement("div");
	flash.id = "flash";
	flash.innerHTML = "Загрузка Flash&hellip;"
	rezult.appendChild(flash);

	div.appendChild(rezult);
	document.getElementsByTagName("body")[0].appendChild(div);

	try{
		/* Try to make SWFObject, if it declare before */
		var so = new SWFObject("http://195.68.160.173/3/imgstc/boltoonz/lp_flv_player.swf", "play_swf", "320", "260", "9.0", "#ffffff");
		so.addVariable("url", url);
		so.write("flash");
	}catch(e){
		var xhr = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
		xhr.open('GET', "/a-xtmpl/robot-1/mode-1/type-js/tmpl-swfobject", true);
		xhr.onreadystatechange = function(){
			if(xhr.readyState == 4 && xhr.status == 200){
				/* JS lazy load throw AJAX */
				eval(xhr.responseText);
				/* SWFObject is global variable after eval */
				var so = new SWFObject("http://195.68.160.173/3/imgstc/boltoonz/lp_flv_player.swf", "play_swf", "320", "260", "9.0", "#ffffff");
				so.addVariable("url", url);
				so.write("flash");
			}
		}
		xhr.send(null);
	}

	return false;
}

var dynbaner = [];
dynbaner.add = function(id){
	this.push(id);
}
dynbaner.reload = function(){
	for(var n =0; n < this.length; n++){
		var el = document.getElementById(this[n]);
		if(el && el.firstChild){
			var cp = el.firstChild.cloneNode(true);
			el.removeChild(el.firstChild);
			el.appendChild(cp);
		}
    }
}