var xmlhttp;
function connect(){
xmlhttp=null;
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
}

function update_votes(mode){
connect();  
var url;
  if (mode==1)
  {
	url="update_votes.php?mode=yes";
	  }
  else if (mode==-1)
  {
	url="update_votes.php?mode=no";
	  }
xmlhttp.onreadystatechange=votes_stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function update_comments(page)
{
connect();  
var url;
url="update_comments.php?start=" + page;
xmlhttp.onreadystatechange=comments_stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function post_comment()
{
var visitor=document.submit_form.visitor.value;
var subject=document.submit_form.subj.value;
var comment=document.submit_form.comment.value;
 if (visitor == "" || subject == ""  || comment == "")
    {
    alert("Value can not be blank!");
    }
else {
	var regX = /\n/gi ;
comment = comment.replace(regX, "<br />");
comment = comment.replace(/(&)/gi, " and ");
connect();
cursor=0;
var url;
url="post_comments.php?visitor=" + visitor + "&sub=" +  subject + "&comment=" + comment ;
xmlhttp.onreadystatechange=comments_stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

}
	
function votes_stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("v_panel").innerHTML=xmlhttp.responseText;
}
}

function comments_stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("c_panel").innerHTML=xmlhttp.responseText;
document.submit_form.visitor.value="";
document.submit_form.subj.value="";
document.submit_form.comment.value="";
scroll(0,0);
}
}


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;
}