// -------------------------------------------------------
// Coded By Mazhar Kaan GIRTI | kaan@girti.com
// 26.03.2009 | Open Source
// -------------------------------------------------------
var RefreshSecond = 5; // second
// -------------------------------------------------------
function KeyStatus(evt, enKey, enFunction, enQuery){
	evt = (evt) ? evt : (window.event) ? event : null
	if (evt){
		var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0))
		if(charCode == enKey){ enFunction(enQuery) }
	}
}
// -------------------------------------------------------
function getChatUser(Word){
	var currentTime = new Date();
	var month = currentTime.getMonth();
	var day = currentTime.getDate();
	var hour = currentTime.getHours();
	var minute = currentTime.getMinutes();
	var second = currentTime.getSeconds();
	var totalTime = Number(month +""+ day +""+ hour +""+ minute +""+ second);
	
	XmlExecute(DomainUrl + "newsChatSystem.php?r=" + roomName + "&t=" + totalTime + "&w=" + Word, getChatUserExecute, "");
}
function getChatUserExecute(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		if (200 == xmlHttp.status){
			var userDataStatus = xmlHttp.responseXML.getElementsByTagName("DATA")[0].childNodes[0].nodeValue;
			var userCount = xmlHttp.responseXML.getElementsByTagName("TOTAL")[0].childNodes[0].nodeValue;
			var allChat = xmlHttp.responseXML.getElementsByTagName("CHAT")[0].childNodes[0].nodeValue;
			document.getElementById("chatUsers").innerHTML = userDataStatus;
			document.getElementById("totalOnline").innerHTML = userCount;
			document.getElementById("chatArea").innerHTML = allChat;
			document.getElementById("chatArea").scrollTop = 100000;
		}
	}
}
getChatUser('');
var chatNow = setInterval("getChatUser('')", (RefreshSecond * 1000));
// -------------------------------------------------------
function sendWord(){
	var getWord = document.getElementById("sendText");
	getChatUser(getWord.value);
	getWord.value = "";
	getWord.focus();
}
function pressKeySend(getEvent){
	KeyStatus(getEvent, 13, sendWord, '1');
}
