/* - - - - - - - - - - - - - - - - - - - - - - -
 JavaScript
 Comments Architecture
 Tuesday, October 13, 2009 11:06 PM
 HAPedit 3.1.11.111
 Written by Perry Mason
 - - - - - - - - - - - - - - - - - - - - - - - */

var xmlhttp
var submitted_type
var submitted_item_id
var submitted_comment
var comment_id

//Called on when someone submits a comment by clicking "Comment"
function addComment(type, item_id, form)
{
xmlhttp=GetXmlHttpObject();
submitted_type = type;
submitted_item_id = item_id;
submitted_comment = form.commentFormInput.value;
if (xmlhttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var url="index2.php?option=com_comprofiler&task=addComment";
//var url="components/com_comprofiler/like.php";
url=url+"&type="+type+"&item_id="+item_id+"&comment="+submitted_comment+"&sid="+Math.random();
//url=url+"&sid="+Math.random();

xmlhttp.onreadystatechange=stateChangedComments;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);

}

//Called on when someone deletes a comment by clicking "Delete"
function deleteComment(comment_id, type, item_id)
{
xmlhttp=GetXmlHttpObject();
submitted_type = type;
submitted_item_id = item_id;
submitted_comment_id = comment_id;

if (xmlhttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var url="index2.php?option=com_comprofiler&task=deleteComment";
url=url+"&comment_id="+submitted_comment_id+"&sid="+Math.random();

xmlhttp.onreadystatechange=stateChangedComments;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

//Called on when the httpRequest responds to the call from addComment or deleteComment
function stateChangedComments()
{

if (xmlhttp.readyState==4)
  {
  document.getElementById("commentArea"+submitted_type+"_"+submitted_item_id).innerHTML=xmlhttp.responseText;
  displayCommentFormLive(submitted_type, submitted_item_id);
  }
}

/*
//Called on if someone clicks "Display all comments" on a comment trail less than 10 comments long
function displayUpdatedCommentArea()
{
xmlhttp=GetXmlHttpObject();
submitted_type = type;
submitted_item_id = item_id;
if (xmlhttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var url="index2.php?option=com_comprofiler&task=displayCommentsLive";
url=url+"&type="+type+"&item_id="+item_id+"&sid="+Math.random();

xmlhttp.onreadystatechange=stateChangedCommentsLive;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}


//Called on when the httpRequest responds to the call from displayUpdatedCommentArea
function stateChangedCommentsLive()
{

if (xmlhttp.readyState==4)
  {
  document.getElementById("commentArea"+submitted_type+"_"+submitted_item_id).innerHTML=xmlhttp.responseText;
  //displayUpdatedCommentArea(submitted_type,submitted_item_id);
  }
}
*/

//Called on if someone clicks "comment" or sets the focus on the mini comment input box
function displayCommentFormLive(type, item_id)
{
xmlhttp=GetXmlHttpObject();
submitted_type = type;
submitted_item_id = item_id;
if (xmlhttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var url="index2.php?option=com_comprofiler&task=displayCommentFormLive";
url=url+"&type="+type+"&item_id="+item_id+"&sid="+Math.random();

xmlhttp.onreadystatechange=stateChangedCommentForm;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

//Called on when the function displayCommentForm makes the request to display the comment form
function stateChangedCommentForm()
{

if (xmlhttp.readyState==4)
  {
  document.getElementById("commentForm"+submitted_type+"_"+submitted_item_id).innerHTML=xmlhttp.responseText;
  }
}



function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

