﻿
var replyObj;
var itemObj;

function editCommentClick(commentID) {
  itemObj = document.getElementById('comment'+commentID);
  if (itemObj) {
    oldReplyContent = itemObj.innerHTML;
    ajaxGet(editOpen, '/ajax_comment.aspx?edit=1&c='+commentID);
  }
  return false;
  
}

function deleteCommentClick(commentID) {

	if (confirm("Are you sure you want to delete this comment? Any replies to the comment will also be deleted.")) {
    itemObj = document.getElementById('comment'+commentID);
    if (itemObj) {
      itemObj.outerHTML='';
      ajaxGet(null, '/ajax_comment_delete.aspx?c='+commentID);
    }
  }
  return false;
  
}

function replyClick(itemID, itemtype, commentID) {

  if (replyObj) {
    replyObj.innerHTML = '';
    replyObj.style.visibility='hidden';   
    replyObj = null;
  }
  replyObj = document.getElementById('reply'+commentID);
  if (replyObj) {
    ajaxGet(replyOpen, '/ajax_comment.aspx?type='+itemtype+'&i='+itemID+'&c='+commentID);
  }
  return false;
  
}

function replyOpen(http_request) {
  if (http_request) {
    if (http_request.readyState == 4) {
      if (http_request.status == 200) {
        replyObj.innerHTML = http_request.responseText;
        replyObj.style.visibility='visible';
        setFocus('txtFull');
      }
    }
  }
}

function editOpen(http_request) {
  if (http_request) {
    if (http_request.readyState == 4) {
      if (http_request.status == 200) {
        itemObj.innerHTML = http_request.responseText;
        setFocus('txtFull');
      }
    }
  }
}

function sendReply(itemID, itemtype, commentID) {
  var txtFull = document.getElementById('txtFull');
  itemObj = document.getElementById('comment'+commentID);
  
  var param = 'type='+itemtype+'&txtFull='+encodeURIComponent(txtFull.value)+'&i='+itemID+'&c='+commentID;
  ajaxPost(replyComplete, '/ajax_comment.aspx', param);  
}

function sendEdit(commentID) {
  var txtFull = document.getElementById('txtFull');
  itemObj = document.getElementById('comment'+commentID);
  
  var param = 'edit=1&txtFull='+encodeURIComponent(txtFull.value)+'&c='+commentID;
  ajaxPost(editComplete, '/ajax_comment.aspx', param);  
}

function replyComplete(http_request) {
  if (http_request) {
    if (http_request.readyState == 4) {
      if (http_request.status == 200) {
        replyObj.innerHTML = "";
        replyObj.style.visibility='hidden';
        itemObj.innerHTML += http_request.responseText;
        replyObj = null;
        itemObj = null;
      }
    }
  }
}

function editComplete(http_request) {
  if (http_request) {
    if (http_request.readyState == 4) {
      if (http_request.status == 200) {
        itemObj.outerHTML = http_request.responseText;
        itemObj = null;
        oldReplyContent = null;
      }
    }
  }
}

function cancelReply() {
    replyObj.innerHTML = "";
    replyObj.style.visibility='hidden';
    replyObj = null;
    oldReplyContent = null;

}

function cancelEdit() {
    itemObj.innerHTML = oldReplyContent;
    itemObj = null;
    oldReplyContent = null;

}

