	function mailcheck()
	{
		if(!document.getElementById('mails') || !document.getElementById('mailcheck'))
		{
			clearInterval(ajax);
			return;
		}
		
		var xmlHttp = false; try { xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { xmlHttp  = false; } } if (!xmlHttp  && typeof XMLHttpRequest != 'undefined') { xmlHttp = new XMLHttpRequest(); }

		var bekannt = parseInt(document.getElementById('mails').innerHTML);
		if (xmlHttp) 
		{
			xmlHttp.open('GET', 'ajax.php?mode=mailcheck', true);
			xmlHttp.onreadystatechange = function ()
			{
				if (xmlHttp.readyState == 4)
				{
					switch(xmlHttp.responseText)
					{
						case '0':
							document.getElementById('mailcheck').innerHTML = 'Keine neuen Nachrichten';
						break;
						
						case '1':
							document.getElementById('mailcheck').innerHTML = '<strong>Eine</strong> neue Nachricht';
						break;
						
						default:
							document.getElementById('mailcheck').innerHTML = '<strong>' + xmlHttp.responseText + '</strong> neue Nachricht';
						break;
					}
					document.getElementById('mails').innerHTML = xmlHttp.responseText;
				
					if(parseInt(xmlHttp.responseText) > bekannt)
					{
						alert('Du hast gerade eine neue Nachricht erhalten!');
					}				
				}
			}
			xmlHttp.send(null);
		}
	}
	
	function ajax()
	{	
		clearInterval(ajax);
		var ajax = setInterval("mailcheck()", 30000);
	}
