if ( navigator.appName == 'Microsoft Internet Explorer' ) {
    var http = new ActiveXObject("Microsoft.XMLHTTP");
    var repl_http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
    var http = new XMLHttpRequest();
    var repl_http = new XMLHttpRequest();
}
var repl_id = -1;
var last_id = -1;

function edit(event) {
	var id = event.substring(5);
	admin = event.substring(0, 4) == 'admi';
	if (last_id != -1) {
		//Closing old window
		repl_id = last_id;
		var cont = document.getElementById('content_' + repl_id);
		
		repl_http.open('get', '/small.php/forum/post/' + repl_id);
		
		repl_http.onreadystatechange = replHandle;
		repl_http.send(null);
	}
	if (id != last_id) {
		//Open the edit window
		var cont = document.getElementById('content_' + id);
		last_id = id;
		
		cont.innerHTML = 'Loading';
		
		http.open('get', '/small.php/forum/edit/' + id + (admin ? '?admin=1' : ''));
		
		http.onreadystatechange = dataHandle;
		http.send(null);
		
	} else {
		last_id = -1;
	}
	return false;
}


function dataHandle() {
	if (http.readyState == 4 && last_id != -1) {
		var response = http.responseText;
		if (response != '') {
			document.getElementById('content_' + last_id).innerHTML = response;
			text_element = document.getElementsByName('content')[0];
		}
	}
}
function replHandle() {
	if (repl_http.readyState == 4 && repl_id != -1) {
		var response = repl_http.responseText;
		if (response != '') {
			document.getElementById('content_' + repl_id).innerHTML = response;
		}
	}
}
