function getRequest(){
	var xmlhttp = null;
	try{
		if ( (navigator.userAgent.indexOf('MSIE') != -1 ) && (navigator.userAgent.indexOf('Win') != -1) ) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			if ( typeof XMLHttpRequest == 'undefined') { return null; }
			xmlhttp = new XMLHttpRequest();
		}
	}
	catch(ex){ return null; }
	return xmlhttp; 
}

function postComment() {
	var ticket_id = document.getElementById("ticket_id").value;
	var nickname = document.getElementById("nickname").value;
	var comment = document.getElementById("comment").value;

	if ( nickname == "" || nickname.length == 0 ){
		alert("Please input your nickname!");
		document.getElementById("nickname").focus();
		return;
	}

	if ( comment == "" || comment.length == 0 ){
		alert("Please input your comment!");
		document.getElementById("comment").focus();
		return;
	}

	var xmlhttp = getRequest();

	nickname = escape(nickname);
	comment = escape(comment);
	var sendstr = "ticket_id=" + ticket_id + "&nickname=" + nickname + "&comment=" + comment;
	xmlhttp.open("POST","AddComment.asp",false);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length",sendstr.length);
	xmlhttp.send(sendstr);

	if ( xmlhttp.responseText == "ok" ){
		alert("Thank you, your reply is updated.");
		document.getElementById("nickname").value="";
		ShowNewMsg(nickname,comment,new Date().toString());
	}else{
		alert("Error, reson is:" + xmlhttp.responseText );
	}

	xmlhttp = null;
}

function ShowNewMsg(nickname,comment,inputdate){
	var objtbl = document.getElementById("tblComments");
	if ( objtbl == null ) { return; }
	var newrow1 = objtbl.insertRow(1);
	var cell = newrow1.insertCell();
	cell.innerHTML = "<font color=\"red\">" +  unescape(nickname) + "New Comment:<br/>" + unescape(comment) + "</font>";
}
