
var receiveReq = new myXMLHttpRequest ();

function makeRequest(url, param) {

 if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {

   document.getElementById('result').innerHTML = '  <img src="/templates/yget/images/action.gif" /> <span style="color:#666;font-weight: bold;font-size:13px">发送中......</span>';
   receiveReq.open("POST", url, true);

   receiveReq.onreadystatechange = updatePage; 

   receiveReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   receiveReq.setRequestHeader("Content-length", param.length);
   receiveReq.setRequestHeader("Connection", "close");

   receiveReq.send(param);
 }   
}


function updatePage() {

 if (receiveReq.readyState == 4) {

   document.getElementById('result').innerHTML = receiveReq.responseText;
   if (receiveReq.responseText != '<fieldset><p class="error"><strong>您输入的验证码有误,请重新输入!</strong></p></fieldset>' && 
		receiveReq.responseText != '<fieldset><p class="error"><strong>请输入评论的内容!</strong></p></fieldset>'){
		document.getElementById('result').id = "anonymous_comments";
		document.getElementById('comment').value = "";
		document.getElementById('tags').value = "";
   }

   img = document.getElementById('imgCaptcha'); 

   img.src = '/create_image.php?' + Math.random();
 }
}


function getParam(theForm) {

 var url = '/captcha.php';

 var postStr = theForm.txtCaptcha.name + "=" + encodeURIComponent( theForm.txtCaptcha.value ) + 
	"&"+theForm.randkey.name+"=" + encodeURIComponent( theForm.randkey.value ) +
	"&"+theForm.link_id.name+"=" + encodeURIComponent( theForm.link_id.value ) +
	"&"+theForm.comment_content.name+"=" + encodeURIComponent( theForm.comment_content.value ) +
	"&"+theForm.user_id.name+"=" + encodeURIComponent( theForm.user_id.value ) ;

 makeRequest(url, postStr);
}
