// Benutzerdefinierte Modulfunktionen
function addsmilie (text) {
   textfeld();
   document.chatbox.message.value  += text + ' ';
   document.chatbox.message.focus();
}

function textfeld () {
   msg = document.getElementById('text');
   if (document.chatbox.message.value == document.chatbox.message.defaultValue) document.chatbox.message.value='';
}

function enterbtn(evt){
    var charCode = (evt.which) ? evt.which : event.keyCode
	if(charCode == "13"){
		saveData();
	}
}




//globale Instanz von XMLHttpRequest
var xmlHttp = false;
var xmlHttp2 = false;
 
//XMLHttpRequest-Instanz erstellen
//... für Internet Explorer
try {
    xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
    xmlHttp2  = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
    try {
        xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
        xmlHttp2  = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
        xmlHttp  = false;
        xmlHttp2  = false;
    }
}
//... für Mozilla, Opera, Safari usw.
if (!xmlHttp  && typeof XMLHttpRequest != 'undefined') {
    xmlHttp = new XMLHttpRequest();
    xmlHttp2 = new XMLHttpRequest();
}
 
//aktuelle Daten laden
loadData();
 
//alle 5 Sekunden neue Daten holen
//setInterval("loadData()",2500);

function loadData()
{
 if (xmlHttp) {
     xmlHttp.open('GET', 'module/chatbox/chatbox_get.php'+ '?rand='+Math.floor(Math.random() * 1000000), true);
     xmlHttp.onreadystatechange = anzeigen;
     xmlHttp.send(null);
     setTimeout("loadData()",5000);
 }
}

function saveData()
{
 if (xmlHttp2) {
     xmlHttp2.open('POST', 'module/chatbox/chatbox_post.php'+'?rand='+Math.floor(Math.random() * 1000000));
     xmlHttp2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
     xmlHttp2.send('message='+document.chatbox.message.value+'&submit='+document.chatbox.submit.value);
     xmlHttp2.onreadystatechange = meldung;
     xmlHttp2.send(null);
 }
 loadData();
}

function delEntry(id)
{
 if (xmlHttp) {
     xmlHttp.open('GET', 'module/chatbox/chatbox_get.php'+ '?delid='+id+'&rand='+Math.floor(Math.random() * 1000000), true);
     xmlHttp.onreadystatechange = anzeigen;
     xmlHttp.send(null);
 }
}

function meldung ()
{
	if(xmlHttp2.readyState == 4) {
		response = xmlHttp2.responseText;
		if (response.length > 20) window.alert(response);
		else {
			document.chatbox.message.value = '';
			document.chatbox.message.focus();
		}
		loadData();
	}
}

function anzeigen()
{
var myDiv2 = document.getElementById("chatbox_content");
if(xmlHttp.readyState == 4)
{
if(xmlHttp.status == 200)
{
try
{
response = xmlHttp.responseText;
//alert(response)
myDiv2.innerHTML =  response;
//setTimeout("loadData()",5000);
}
catch (e)
{
//alert("Kann nicht von Serverdatei lesen (bei Namen)"  + e.toString());
}
}
else 
{
/*alert(xmlHttp.status);*/
}
}
}
