// CSME.PRO [  Encode in UTF-8  Without BOM ] [ ☺ ]

function peopleUpdated(txt){
	var parts =	txt.split(/\|/,2);

	gid("tempOnlines").innerHTML = parts[1];
	var onlines = parts[0].split(/\,/g);
	var found = false;
	var old = document.onlines;
	for(var i in onlines){
		found = false;
		for(var j in document.onlines){
			if(onlines[i] == document.onlines[j]){
				found = true;
				delete(old[j]);
			}
		}
		if(!found){
			gid("onlines").appendChild(gid("mem" + onlines[i]));
		}
	}
	gid("tempOnlines").innerHTML = "";
	for(i in old){
		try{
			gid("onlines").removeChild(gid("mem" + old[i]));
		}catch(e){}
	}
	document.onlines = onlines;
	document.updateChatTO = setTimeout("document.updateChat();",10000);
}

function updateChatRoom(){
	clearTimeout(document.updateChatTO);
	LoadAjaxData('index.php','&dir=site&page=chat&op=populate_chat_people&onlines=' + document.onlines.join(","),peopleUpdated);
}

function updateChatButton(mem,tx){
	if(mem != "" && tx != ""){
		document.ca_btn = gid("chatAnchor");
		clearTimeout(document.ca_btn.stopNotification);
		document.ca_btn.blinkX = setInterval(function(){
				if(document.ca_btn.style.color.substr(0,1) == "#"){
					if(document.ca_btn.style.color == "#ffffff"){
						document.ca_btn.style.color = "#ff0000";
					}else{
						document.ca_btn.style.color = "#ffffff";
					}
				}else{
					if(document.ca_btn.style.color == "rgb(255, 255, 255)"){
						document.ca_btn.style.color = "#ff0000";
					}else{
						document.ca_btn.style.color = "#ffffff";
					}
				}
			},500);
		document.ca_btn.stopNotification = setTimeout(function(){
				clearInterval(document.ca_btn.blinkX);
				document.ca_btn.style.color = "#ffffff";
			},7500);
		gid("chatNotifications").innerHTML = '<div style="white-space:nowrap;background:#ffeeee;">' + tx + '</div>';
			
	}
}
function chatWith(mem){
	gid("chatText").disabled="";
	if(gid("chatChain" + mem) == undefined){
		var nd = document.createElement("DIV");
		nd.id = "chatChain" + mem;
		gid("chatChains").appendChild(nd);		
	}
	var cc = gid("chatChains").childNodes;
	var ccMem = "";
	for(var d in cc){
		if(cc[d].nodeType == 1){
			if(cc[d].tagName == "DIV"){
				ccMem = cc[d].id.replace("chatChain","");
				if(cc[d].id == ("chatChain" + mem)){
					cc[d].style.display = "block";
				}else{
					if(ccMem != ""){
						try{
							gid("cur" + ccMem).style.display = "none";
						}catch(e){}
					}
					cc[d].style.display = "none";
				}
			}
		}
	}
	gid("chatText").focus();
	gid("member_pic").src = gid("pic" + mem).src;
	gid("cur" + mem).style.display = 'inline';
	gid("chatDetails").innerHTML = gid("det" + mem).innerHTML;
	gid("inp_member").value = mem;
}
function updateChainX(mem,tx){
	if(gid("chatChain" + mem) == undefined){
		var nd = document.createElement("DIV");
		nd.id = "chatChain" + mem;
		nd.style.display = "none";
		nd.style.overflowY = "scroll";
		nd.style.width = "100%";
		nd.style.height = "213px";
		gid("chatChains").appendChild(nd);
	}
	gid("chatChain" + mem).innerHTML += tx;
	if(tx){
		gid("chatChain" + mem).scrollTop = gid("chatChain" + mem).scrollHeight;
		if(document.me != mem){
			clearTimeout(gid("say" + mem).hideX);
			gid("say" + mem).style.display = 'inline';
			var to_str = "gid('say" + mem + "').style.display = 'none';";
			gid("say" + mem).hideX = setTimeout(to_str,5000);
		}
	}
}

function read_chat(){
	LoadAjaxData('chatReader.php','&member=' + document.me ,chat_read);
}

function chat_read(txt){
	if(document.chatNotes == undefined){
		document.chatNotes = [];
	}
	clearTimeout(document.chatReaderI);
	var more = "";
	if(txt != ''){
		var spl = txt.split("\n");
		var lspl = spl.length;
		for(var i = 0 ; i < lspl ; i++ ){
			var spltx = spl[i];
			if(spltx){
				splt = spltx.split("|",2);
				var mem = splt[0];
				var tx = splt[1];
				document.updateChains(mem,tx);
			}
		}
	}
	if(more != ''){
		chat_read(more);
	}else{
		document.chatReaderI = setTimeout("read_chat();",document.chat_refresh_rate);
	}
}
