firstscroll = true;
function get_Xhr() {
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   try { return new XMLHttpRequest(); } catch(e) {}
   alert("AJAX n'est pas supporté par votre navigateur");
   return null;
  }
function updateChat() {

  var xhr = get_Xhr();
  
  if(xhr && xhr.readyState != 0) {
    xhr.abort();
  }


  xhr.open('POST', '../getmsg.php', true);
  xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  xhr.send('');
  
  xhr.onreadystatechange = function(){
    if(xhr.readyState == 4) {	
		//alert(xhr.responseText);
		if(xhr.status == 200)  {
			
			scrollornot = document.getElementById('chat').scrollHeight == document.getElementById('chat').scrollTop;
			document.getElementById('chat').innerHTML = xhr.responseText;
			if (scrollornot || firstscroll) {
				if (firstscroll)
					firstscroll = false;
				document.getElementById('chat').scrollTop = document.getElementById('chat').scrollHeight;
			}
			setTimeout('updateChat()', 5000);
	  }
    }
  };
}

