//$Id: $
function add_comment() {
   var comments_text = document.getElementById("comments_text").value;
   comments_text = new String(comments_text);
   comments_text = comments_text.replace( /^\s+/g, "" );// strip leading
   if (comments_text == "") {
      alert("Please enter a comment.");
      document.getElementById("comments_text").focus();
      return false;
   }
   else {
      var poststr = "d=add&obj_id=" + encodeURI( document.getElementById("obj_id").value ) +
          "&type_cd=" + encodeURI( document.getElementById("type_cd").value ) +
          "&comments_text=" + encodeURIComponent( document.getElementById("comments_text").value );
      makePOSTRequest('user_comment.php', poststr, 'user_comments');
   }
}

function show_comment_form(user_logged_in, current_url) {
   if (user_logged_in == 1) {
      show('comment_form');
   }
   else {
      location.href="http://" + location.hostname + "/user_admin.php?d=user_login&url=" + current_url;
   }
}

function vote_comment(user_logged_in, current_url, comment_id, vote) {
   if (user_logged_in == 1) {
      var comment_creator = document.getElementById("comment_creator_" + comment_id).value;
      var comment_voter = document.getElementById("comment_voter_" + comment_id).value;
      if (comment_creator == comment_voter) {
         alert("You can not vote on comment written by you");
         return false;
      }
      else {
         url  = 'http://' + location.hostname + '/user_comment.php?d=vote&comment_id=' + comment_id + '&vote=' + vote;
         loadDoc(url, "comment_votes_" + comment_id);
      }
   }
   else {
      location.href="http://" + location.hostname + "/user_admin.php?d=user_login&url=" + current_url;
   }
}
