var obj = null;

if (window.XMLHttpRequest) {
	obj = new XMLHttpRequest();
} else if (window.ActiveXObject) {
	obj = new ActiveXObject("Microsoft.XMLHTTP");
}


function register(){

	var target = document.getElementById("regAnswer");
	if (answer) {
		if (obj) {
			obj.open("GET", "/actions/registerNewUser.php?postId=" + id);
			obj.onreadystatechange = function() {
				if (obj.readyState == 4 && obj.status == 200) {
					target.innerHTML = obj.responseText;
				}
			}
			obj.send(null);
		}
	}
}

function sendMessage() {

	var message = document.getElementById("message").value;
	var subject = document.getElementById("subject").value;
	var to = document.getElementById("to").value;
	var url = "/actions/sendMessage.php";
	var params = "message=" + encodeURIComponent(message) + "&subject=" + encodeURIComponent(subject) + "&to=" + encodeURIComponent(to);
	onComplete = function() {
		alert("Wiadomość została wysłana.");
		if (location.href.match('poczta')) {
			location.reload();
		} else {
			location.href = location.href + '/poczta';
		}
	}
	onEnd = function() {}
	startPOSTRequest(url, params, onComplete, onEnd);

}

function msgReply(id){
	document.getElementById("subject").value = 'RE: ' + document.getElementById("subject"+id).innerHTML;
	document.getElementById("to").value = document.getElementById("recipient"+id).innerHTML;
}

function msgMarkAsRead(id) {
	if (obj) {
		obj.open("GET", "/actions/msgMarkAsRead.php?id=" + id);
		obj.onreadystatechange = function() {
			if (obj.readyState == 4 && obj.status == 200) {
				document.getElementById("msgStatus"+id).src = '/images/mail1.gif';
			}
		}
		obj.send(null);
	}

}
