/*********************************************
 *                                           *
 *  Copyright united-photographers.com 2004  *
 *                                           *
 *********************************************
 * Author:                                   *
 * Thomas Wiedenhöft (wiedenhoeft-gailat.de) *
 *                                           *
 ********************************************/

function makeRequest(cline)/*{{{*/
{
	uri=base_uri;
	if(chat_line!="")
		uri=uri+"&cln="+chat_line;

	http_request = false;
	if (window.XMLHttpRequest)
	{ // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType)
		{
			http_request.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject)
	{ // IE
		try
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e)
		{
			try
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	chat_line="";

	if (!http_request)
	{
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = showContents;
	http_request.open('GET', uri, true);
	http_request.send(null);

	window.setTimeout("makeRequest('')",1000);
}/*}}}*/

function showContents()/*{{{*/
{
	if(http_request==null)
	{
		http_request=false;
		return;
	}
	if (http_request.readyState == 4 && http_request.status == 200)
	{
		tt=0;
		line_arr = http_request.responseText.split("|||");

		for(j=0;j<line_arr.length;j++)
		{
			if(line_arr[j]!="")
			{
				ln_arr = line_arr[j].split("^");
				if(ln_arr[0]==myid)
					aclass="cht_txt1";
				else
					aclass="cht_std1";

				newLn = document.createElement("div");
				newCl = document.createAttribute("class");
				newCl.nodeValue=aclass;

				nTxt = document.createTextNode(ln_arr[2]);
				newLn.appendChild(nTxt);

				newLn.setAttributeNode(newCl);
				document.getElementById("chatpane").appendChild(newLn);

				i=3;
				for(;i<ln_arr.length;i++)
				{
					newLn = document.createElement("div");
					newCl = document.createAttribute("class");
					newCl.nodeValue="cht_txt";

					nTxt = document.createTextNode(ln_arr[i]);
					newLn.appendChild(nTxt);

					newLn.setAttributeNode(newCl);
					document.getElementById("chatpane").appendChild(newLn);
				}
				if(i>3)
				{
					newLn = document.createElement("br");
					document.getElementById("chatpane").appendChild(newLn);
					newLn.scrollIntoView("true");
				}
			}
		}
	}
	else
	{
		return;
		tt++;
		if(tt>5)
		{
			tt=0;
			newLn = document.createElement("div");
			newCl = document.createAttribute("class");
			nTxt = document.createTextNode("no connection!");
			newCl.nodeValue="cht_err";
			newLn.appendChild(nTxt);
			newLn.setAttributeNode(newCl);
			document.getElementById("chatpane").appendChild(newLn);
			newLn.scrollIntoView("true");

			return;
		}
	}
}/*}}}*/

function sendChatLine()/*{{{*/
{
	cline=document.chat_form.chat_ln.value;
	if(cline!="")
	{
		chat_line=encodeURIComponent(cline);
	}
	document.chat_form.chat_ln.value="";
	return(false);
}/*}}}*/
