var xmlHttp;
function postcomment(nid) {
	if(window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
	var querystring = "nid=" + nid;
	querystring += "&poster=" + encodeURI(document.getElementById("poster").value);
	querystring += "&comment=" + encodeURI(document.getElementById("commentbody").value);
	xmlHttp.open("POST", "comments.php");
	xmlHttp.onreadystatechange = callback;
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
	xmlHttp.send(querystring);
}
function getcomments(nid) {
	if(window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
	xmlHttp.open("POST", "comments.php");
	xmlHttp.onreadystatechange = callback;
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
	xmlHttp.send("nid="+nid);
}

function callback() {
	if((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) {
		document.getElementById("comments").innerHTML = xmlHttp.responseText;
	} else if((xmlHttp.readyState == 4) && (xmlHttp.status == 404)) {
		document.getElementById("comments").innerHTML = "<p>コメントがありません。</p>";
	} else {
		document.getElementById("comments").innerHTML = "<p><img src='../graphics/ajax-loader.gif' alt='Loading...' width='31' height='31' /> データ取得中…</p>";
	}
}
