function addcomment(id) {
    request = GetXmlHttpObject();
    if (request==null) {
      alert ("Your browser does not support AJAX!");
      return;
    }
    document.comment_form.submit.disabled=true;
    
    var url = "http://www.rateatemp.com/add_comment.php";
    var len = document.comment_form.rating.length;
    var param = "test=0";
  
    param += "&id="+escape(encodeURI(id));
    for (i=0; i<len; i++) {
      if (document.comment_form.rating[i].selected) {
        param += "&rating="+escape(encodeURI(document.comment_form.rating[i].value));
      }
    }
    param += "&name="+escape(encodeURI(document.comment_form.name.value));
    param += "&captcha="+escape(encodeURI(document.comment_form.captcha.value));
    param += "&comment="+escape(encodeURI(document.comment_form.comment.value));

    request.onreadystatechange = updatecomments;
    request.open("POST", url, true);
    request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    request.setRequestHeader("Content-length", param.length);
    request.setRequestHeader("Connection", "close");
    request.send(param);
}

function updatecomments() {
    if (request.readyState == 4) {
        if (request.status == 200) {
            var code="";
            var error="<p style=\"text-align: left;\">";
            var count;
            
            var message_div = document.getElementById("new_message");
            var error_div = document.getElementById("message");
            
            var xmldoc = request.responseXML;
            var error_nodes = xmldoc.getElementsByTagName("error");
            var comment_node = xmldoc.getElementsByTagName("comment");

	    var error_length = error_nodes.length;
	    for (i=0; i<error_length; i++) {
	        if (error_nodes[i].attributes.length > 0) {
	            count = error_nodes[i].getAttribute("id");
	            error += "<span style=\"color: #"+error_nodes[i].getElementsByTagName("color")[0].childNodes[0].nodeValue+"\">";
	            if (count!=0) {
	                error += count+". ";
	            }
	            error += error_nodes[i].getElementsByTagName("message")[0].childNodes[0].nodeValue+"</span>";
	            if (i<error_length) {
	                error += "<br/>";
	            }
	        }
	    }
	    error += "</p>";
	    error_div.innerHTML = error;
	  
	    if (count == 0) {
                var rating_node = parseInt(comment_node[0].getElementsByTagName("rating")[0].childNodes[0].nodeValue);
                var author_node = comment_node[0].getElementsByTagName("author")[0].childNodes[0].nodeValue;
                var date_node = comment_node[0].getElementsByTagName("date")[0].childNodes[0].nodeValue;
                var text_node = comment_node[0].getElementsByTagName("text")[0].childNodes[0].nodeValue;

                code = '<div class="content_heading">';
                for (i=0; i<5; i++) {
                    if (i < rating_node) {
            	        code += '<img src="http://www.rateatemp.com/images/fullstar.gif" />';
            	    } else {
            	        code += '<img src="http://www.rateatemp.com/images/emptystar.gif" />';
            	    }
                }
                code += ' - ';
                code += author_node;
                code += ' - <i>';
                code += date_node;
                code += '</i></div><p style="padding-left: 5px; padding-right: 5px;">';
                code += text_node;
                code += '</p>';

                message_div.style.display = "block";
                message_div.innerHTML = code;
            }
        } else if (request.status == 404) {
	    alert("Request URL does not exist");
	} else {
	    alert("Error: status code is " + request.status);
        }
    }
    document.comment_form.submit.disabled=false;
}