
function OpenIMChat(login,second){
	var urll = "/a-iminit/"+(login? ("ulogin-"+login+"/") : "");
	var wnd = window.open("","imwindow",
	"width=1030,height=780,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);}
}

var window_isfocus = false;
function isFocus(focus, say){
	if(window_isfocus == focus) return;
	if(say){ try{ 
		if(window.document['exchange'].setFocus(focus? true : false)) window_isfocus = focus;
	}catch(e){}; } else window_isfocus = focus;
}

if (window.addEventListener){
	window.addEventListener('focus', function(){ isFocus(true, true); }, false);
	window.addEventListener('blur', function(){ isFocus(false, true); }, false);
	document.addEventListener('mouseover', function(){ isFocus(true, true); }, false);
}else{
	window.attachEvent('onfocus', function(){ isFocus(true, true); });
	window.attachEvent('onblur', function(){ isFocus(false, true); });
	document.attachEvent('onmouseover', function(){ isFocus(true, true); });
}

function NumFormat(num, sep){
	num = parseInt(num).toString();
	var regEx = /(-?\d+)(\d{3})/;
	while (regEx.test(num)) { num = num.replace(regEx,"$1"+sep+"$2"); }
	return num;
}

function SetIMMsg(nmes, cnt_new, cnt_onl, cnt_up){
	var el1 = document.getElementById("immessage_n");
	var el2 = document.getElementById("immessage");
	if(el1) el1.innerHTML = nmes? nmes : '0';
	if(el2) el2.className = nmes? 'messagenew' : 'message';
	
	if((el1 = document.getElementById("cntnew")) && cnt_new){
		el1.innerHTML = NumFormat(cnt_new, ',');
	}
	
	if((el1 = document.getElementById("cntonl")) && cnt_onl){
		el1.innerHTML = NumFormat(cnt_onl, ',');
	}
	
	if((el1 = document.getElementById("cntup")) && cnt_up){
		el1.innerHTML = NumFormat(cnt_up, ',');
	}
	
}

function OpenIMMsg(ischat){
	var nm = document.getElementById("immessage_n").innerHTML;
	if(nm != '0'){
		//document.getElementById("immessage_n").innerHTML = nm - 1;
		if(ischat) fw.chat.fChtNewContact();
		else OpenIMChat();
	}
}

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);
		}
    }
}
