function editCommentSubmit(){
   createRequest();
   var entity_id = document.getElementById("entity_id").value;
   var entity_type = document.getElementById("entity_type").value;
   var comment = document.getElementById("comment").value;
   var edit_to = document.getElementById("edit_to").value;
   var url = "/comments/edit_comment.php";
   request.open("POST", url, true);
   request.setRequestHeader("Content-Type",
			    "application/x-www-form-urlencoded");
   request.onreadystatechange = updatePageEditted;
   request.send("comment_editted=" + escape(comment)+
		"&comment=" + escape(edit_to) +
                "&entity_id="+escape(entity_id)+"&entity_type="+escape(entity_type));
}
function deleteComment(comment){
   var answer = confirm("Are you sure you want to delete this comment?");
   if( answer  ){
      createRequest();
      var entity_id = document.getElementById("entity_id").value;
      var entity_type = document.getElementById("entity_type").value;
      var url = "/comments/delete_comment.php?comment="+comment+
	"&entity_id="+escape(entity_id)+"&entity_type="+escape(entity_type)+"&rand="+Date();
      request.open("GET", url, true);
      request.onreadystatechange = updatePage;
      request.send(null);
   }
}
function deprecateComment(comment){
   if( comment > 0 ){
      var answer = confirm("Are you sure you want to deprecate this comment?");
   } else {
      var answer = confirm("Are you sure you want to undeprecate this comment?");
      comment = Math.abs(comment);
   }
   if( answer  ){
      createRequest();
      var entity_id = document.getElementById("entity_id").value;
      var entity_type = document.getElementById("entity_type").value;
      var url = "/comments/deprecate_comment.php?comment="+comment+
	    "&entity_id="+escape(entity_id)+"&entity_type="+escape(entity_type)+"&rand="+Date();
	    request.open("GET", url, true);
	    request.onreadystatechange = updatePage;
	    request.send(null);
   }
}
function editComment(comment){
   createRequest();
   var entity_id = document.getElementById("entity_id").value;
   var entity_type = document.getElementById("entity_type").value;
   var url = "/comments/edit_comment.php?comment="+comment+
	 "&entity_id="+escape(entity_id)+"&entity_type="+escape(entity_type)+"&rand="+Date();
      request.open("GET", url, true);
      request.onreadystatechange = editCommentDisplay;
      request.send(null);
}
function cancelEdit(comment){
   createRequest();
   var entity_id = document.getElementById("entity_id").value;
   var entity_type = document.getElementById("entity_type").value;
   var url = "/comments/edit_comment.php?cancel=1"+
	    "&entity_id="+escape(entity_id)+"&entity_type="+escape(entity_type)+"&rand="+Date();
	 request.open("GET", url, true);
	 request.onreadystatechange = editCommentDisplay;
	 request.send(null);
}
function updatePageEditted(){
   if (request.readyState == 4) {
      var currentComments = document.getElementById('display-comments');
      currentComments.innerHTML = request.responseText;
      cancelEdit();
      if( window.location.hash == '#reply' ){
          window.location.hash= "#";
      }
   }
}
function editCommentDisplay(){
   if(request.readyState == 4){
      var displayReply = document.getElementById('display-form');
      displayReply.innerHTML = request.responseText;
   }
}

