function createRequestObject() {
	var requestobject;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		requestobject = new ActiveXObject("Microsoft.XMLHTTP");
		}else{
		requestobject = new XMLHttpRequest();
	}
	return requestobject;
}

var http = createRequestObject();
var send = createRequestObject();


function ajaxedit(postid,actual) {

	elem = document.getElementById("content" + postid);
	http.open('get','./ajax.php?action=getpostcontent&postid=' + postid + '&random=' + encodeURIComponent(new Date()));
	http.onreadystatechange= function() { getContent(postid);return true; }
	http.send(null);
}

function getContent(postid){
	if(http.readyState == 4){
		elem = document.getElementById("content" + postid);
		content=http.responseText;
		elem.innerHTML = "<textarea style=\"width:100%;\" id=\"test\" rows=\"10\"  onblur=\"return ajaxBlur(this," + postid + ")\">" + content + "</textarea>";
		elem.firstChild.focus();
	}
}


function ajaxBlur(ajaxtextarea,postid) {
	if (ajaxtextarea.value!="") {
		var text = ajaxtextarea.value.replace("/\|/","");
		send.open('post','./ajax.php',true);
		send.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		send.send('action=updatepost&postid=' + postid + '&newmessage=' + escape(text) + '&random=' + encodeURIComponent(new Date()));
		send.onreadystatechange= function() { updateContent(postid);return true; }
		
	}
return true;
}

function updateContent(postid){

	if(send.readyState == 4){
		elem1 = document.getElementById("content" + postid);
		content=send.responseText;
		elem1.innerHTML = "<span ondblclick=\"ajaxedit(" + postid + ",this);\">" + content + "</span>";
	}
}

