var http = createRequestObject();

function createRequestObject() {
	var xmlhttp;
	try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
  catch(e) {
    try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
    catch(f) { xmlhttp=null; }
  }
  if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
  	xmlhttp=new XMLHttpRequest();
  }
	return  xmlhttp;
}

function type_message(roomId,guest,message,sid){
	
	time_added = 0;
	
	if(sid == 2){
		document.getElementById('input_'+roomId).value = "";
	}

	if(sid == 1){
		
		setCookie("type_"+roomId,0,"1");
		
		time_added = parseInt(getCookie("type_"+roomId));
		
		if(time_added <= 1){
			time_added++;
			setCookie("type_"+roomId,time_added,"1");
		}
		
		return false;
	}
	
	var now = Math.round((99977562 - 10016486) * Math.random() + 1) + 22423;
	message = encodeURIComponent(message);
	patch = "./type.php?sid="+sid+"&guest="+guest+"&message="+message+"&now="+now;
	
    http.open("GET",patch,true);
    http.onreadystatechange = function(){
   
  		if((http.readyState == 4)&&(http.status == 200)){
    		 var response = http.responseText;
    	}
    }
	http.send(null);
	
	if(sid == 2){
		to = setTimeout("history("+roomId+")", 250);
	}

}

function enter_pressed(e){
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return false;
return (keycode == 13);
}
