function ajaxFunction(){
	var ajaxRequest;
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				//browsers all not support, rare case
				return false;
			}
		}

	}
	return ajaxRequest;
}
var stoperan = 0;
function showData() {
	htmlRequestw = ajaxFunction();
	if (htmlRequestw==null){ // If it cannot create a new Xmlhttp object.
		return;
	} 
	tagTalkOkno1 = document.getElementById("tagTalk");
	tagTalkOkno2 = document.getElementById("tagTalk2");
	htmlRequestw.onreadystatechange = function(){
		if(htmlRequestw.readyState == 4){
			if(tagTalkOkno1) {
				tagTalkOkno1.innerHTML = htmlRequestw.responseText;
			}
			if(tagTalkOkno2) {
				tagTalkOkno2.innerHTML = htmlRequestw.responseText;
			}
		}
	}
	var ts = Math.round(new Date().getTime() / 1000);
	htmlRequestw.open("GET", "tagTalk_"+pokoj_get+".txt?"+ts, true);
	htmlRequestw.send(null); 
}
function sendMsg() {
	if(stoperan == 0) {
		stoperan = 1;
		setTimeout('stoperan = 0', 10000);
		htmlRequestx = ajaxFunction();
		if (htmlRequestx==null){ // If it cannot create a new Xmlhttp object.
			return;
		} 
		htmlRequestx.onreadystatechange = function(){
			if(htmlRequestx.readyState == 4){
				eval(htmlRequestx.responseText);
			}
		}
		msg = document.getElementById('tagTalkMsg').value;
		pokoj = document.getElementById('pokoj').value;
		htmlRequestx.open("POST", "includes/sendTagTalk.php");
		htmlRequestx.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		htmlRequestx.send("msg="+msg+"&pokoj="+pokoj); 
		document.getElementById('tagTalkMsg').value = '';
	}
	else {
		alert("Musisz chwilkę poczekać zanim napiszesz kolejną wiadomość.");
	}
	return false;
}

showData();
setInterval("showData()",2000);
