// JavaScript Document
var xmlHttp

function displayLoading(element) { 
  while (element.hasChildNodes()) { 
    element.removeChild(element.lastChild); 
  } 
  var image = document.createElement("img"); 
  image.setAttribute("src","indicator.gif"); 
  image.setAttribute("alt","Loading..."); 
  element.appendChild(image); 
} 


function getComments(news_id, curPage){ 
displayLoading(document.getElementById("comments_list")); 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
 alert ("Browser does not support HTTP Request")
 return
 }
var url="ajax_get_news_comments.php"
url=url+"?news_id="+news_id;
url=url+"&curPage="+curPage;
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=commentStateChanged;
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function getReviewComments(review_id, curPage){ 
displayLoading(document.getElementById("comments_list")); 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
 alert ("Browser does not support HTTP Request")
 return
 }
var url="ajax_get_review_comments.php"
url=url+"?review_id="+review_id;
url=url+"&curPage="+curPage;
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=commentStateChanged;
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}


function submitComment(data){ 
	displayLoading(document.getElementById("comments_list")); 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		 return
	 }
	var url="processComment.php";
	url=url+"?sid="+Math.random();
	xmlHttp.onreadystatechange=commentStateChanged ;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.send(data);
}

function submitReviewComment(data){ 
	displayLoading(document.getElementById("comments_list")); 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
		 return
	 }
	var url="processReviewComment.php";
	url=url+"?sid="+Math.random();
	xmlHttp.onreadystatechange=commentStateChanged ;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.send(data);
}


function commentStateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
 		document.getElementById("comments_list").innerHTML=xmlHttp.responseText;
		prepareForm();
 	} 
}


function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
