var xmlHttp;
var topic_id;
var item_id;

function favorite_click(topicid)
{
	var answer = confirm("Would you like to add this topic to your favorites?")
	if (answer){
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		 {
			alert ("Browser does not support HTTP Request");
			return;
		}
		var url="addfav.php";
		url=url+"?topicid="+topicid;
		xmlHttp.onreadystatechange=addFavorite;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	else{

	}
}

function addFavorite()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 	alert(xmlHttp.responseText);
 } 
}

function flag_click(topicid)
{
	var answer = confirm("Would you like to flag this topic as inappropriate?")
	if (answer){
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		 {
			alert ("Browser does not support HTTP Request");
			return;
		}
		var url="addflag.php";
		url=url+"?topicid="+topicid;
		xmlHttp.onreadystatechange=addFlag;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	else{

	}
}

function addFlag()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 	alert(xmlHttp.responseText);
 } 
}

function nsfw_click(topicid)
{
	var answer = confirm("Would you like to label this topic as NSFW?")
	if (answer){
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null)
		 {
			alert ("Browser does not support HTTP Request");
			return;
		}
		var url="addnsfw.php";
		url=url+"?topicid="+topicid;
		xmlHttp.onreadystatechange=addNsfw;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	else{

	}
}

function addNsfw()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 	alert(xmlHttp.responseText);
 } 
}

function deleteItem(id)
{

if (confirm("Are you sure you want to delete this item?"))
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
var url="deleteitem.php";
url=url+"?id="+id;
xmlHttp.onreadystatechange=itemDeleted;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

}

function itemDeleted()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 	location.href=location.href;
 } 
}

function deleteTopic(id)
{

if (confirm("Are you sure you want to delete this topic?"))
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
var url="delete.php";
url=url+"?id="+id;
xmlHttp.onreadystatechange=topicDeleted;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

}

function topicDeleted()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 	location.href=location.href;
 } 
}

function voteTopic(id,user,val)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
var url="vote.php";
url=url+"?id="+id;
url=url+"&user="+user;
url=url+"&val="+val;
topic_id=id;
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("numvotes_"+topic_id).innerHTML=xmlHttp.responseText;
 } 
}

function voteItem(id,user,val)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
var url="voteitem.php";
url=url+"?id="+id;
url=url+"&user="+user;
url=url+"&val="+val;
item_id=id;
xmlHttp.onreadystatechange=stateChangedItem;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChangedItem() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("itemvotes_"+item_id).innerHTML=xmlHttp.responseText;
 } 
}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;
}

function showPicture(pic)
{
	picImg2 = document.getElementById('picImg');
	picImg2.src = pic;

      document.getElementById('picDivUnder').style.visibility = 'visible';
      document.getElementById('picDiv').style.visibility = 'visible';
}

function killPic()
{
      document.getElementById('picDivUnder').style.visibility = 'hidden';
      document.getElementById('picDiv').style.visibility = 'hidden';
}