function submitThatWasMe()
{
	
	var strPhotoId = document.getElementById("photoid").value;
	var strLoggedInUserId = document.getElementById("loggedinuserid").value;
	var strJustification = document.getElementById("justification").value;
	
	if (strJustification.length == 0)
	{
		alert('You must type a few words to prove you are in the photo first!');
		return;
	}
	
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		// Browser does not support HTTP Request
		return;
	} 
	
	var url="doThatWasMe.php";
	url=url+"?photoid="+strPhotoId;
	url=url+"&action=submitTWM";
	url=url+"&userid="+strLoggedInUserId;
	url=url+"&justification="+strJustification;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChangedSubmitTWM;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}

function addComment()
{
	
	var strPhotoId = document.getElementById("photoid").value;
	var strLoggedInUserId = document.getElementById("loggedinuserid").value;
	var strComment = document.getElementById("comment").value;
	
	if (strComment.length == 0)
	{
		alert('Type a comment in the textbox first!');
		return;
	}
	
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		// Browser does not support HTTP Request
		return;
	} 
	
	var url="doThatWasMe.php";
	url=url+"?photoid="+strPhotoId;
	url=url+"&action=addcomment";
	url=url+"&userid="+strLoggedInUserId;
	url=url+"&comment="+strComment;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChangedAddComment;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}

function confirmLurker(lurkerid, photoid, userid)
{
	
	if (lurkerid.length == 0)
	{
		return;
	}
	
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		// Browser does not support HTTP Request
		return;
	} 
	
	var url="doThatWasMe.php";
	url=url+"?lurkerid="+lurkerid;
	url=url+"&photoid="+photoid;
	url=url+"&userid="+userid;
	url=url+"&action=confirmLurker";
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChangedConfirmLurker;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}

function rejectLurker(lurkerid, photoid, userid)
{
	
	if (lurkerid.length == 0)
	{
		return;
	}
	
	xmlHttp = GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		// Browser does not support HTTP Request
		return;
	} 
	
	var url="doThatWasMe.php";
	url=url+"?lurkerid="+lurkerid;
	url=url+"&photoid="+photoid;
	url=url+"&userid="+userid;
	url=url+"&action=rejectLurker";
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChangedRejectLurker;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	
}

function stateChangedSubmitTWM() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		//alert(xmlHttp.responseText);
		showInfoPanel();
	} 
} 

function stateChangedConfirmLurker() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		//alert(xmlHttp.responseText);
		showConfirmedPanel();
	} 
} 

function stateChangedRejectLurker() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		//alert(xmlHttp.responseText);
		showRejectedPanel();
	} 
} 

function stateChangedAddComment() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		var x = document.getElementById('tbCommentPanel').insertRow(1);
		x.vAlign = "top";
		x.innerHTML = xmlHttp.responseText;
		
		var tdAddCommentPanel = document.getElementById("tbCommentPanel").rows[0].cells[0];
		tdAddCommentPanel.innerHTML = "<span class=\"greyNormalSpan\"><a href=\"javascript:showAddCommentForm()\" class=\"greenLink\">Post your own comment here</a></span>";
	} 
} 

function GetXmlHttpObject(handler)
{ 
	var objXMLHttp=null;
	
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	return objXMLHttp
}

function showConfirmedPanel()
{
	var tdInfoPanel = document.getElementById("tdInfoPanel");
	
	var strTemp = "<span class=\"greyLargeBoldSpan\">Congratulations!</span>";
	strTemp += "<br/>";
	strTemp += "<span class=\"greyNormalSpan\">You have found a lurker in this photograph. Well done!</span>";
	strTemp += "<br/><br/>";
	strTemp += "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
	strTemp += "<tr><td valign=\"top\" align=\"center\"><a href=\"javascript:window.location.reload(true);\" class=\"largeWhiteLink\">Continue</a></td>";
	strTemp += "</tr></table>";
	
	tdInfoPanel.innerHTML = strTemp;
}

function showRejectedPanel()
{
	var tdInfoPanel = document.getElementById("tdInfoPanel");
	
	var strTemp = "<span class=\"greyLargeBoldSpan\">Oh well...</span>";
	strTemp += "<br/>";
	strTemp += "<span class=\"greyNormalSpan\">So, this wasn't a lurker. Never mind!</span>";
	strTemp += "<br/><br/>";
	strTemp += "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
	strTemp += "<tr><td valign=\"top\" align=\"center\"><a href=\"javascript:window.location.reload(true);\" class=\"largeWhiteLink\">Continue</a></td>";
	strTemp += "</tr></table>";
	
	tdInfoPanel.innerHTML = strTemp;
}

function showInfoPanel()
{
	var tdInfoPanel = document.getElementById("tdInfoPanel");
	
	var strTemp = "<span class=\"greyLargeBoldSpan\">The notification has been sent!</span>";
	strTemp += "<br/>";
	strTemp += "<span class=\"greyNormalSpan\">The owner of the photo has been notified by email that you believe you are a lurker. It's their decision that is final, and you will be notified either way by e-mail or by logging on to your user page. Good luck!</span>";
	strTemp += "<br/><br/>";
	strTemp += "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
	strTemp += "<tr><td valign=\"top\" align=\"center\"><a href=\"javascript:window.location.reload(true);\" class=\"largeWhiteLink\">Continue</a></td>";
	strTemp += "</tr></table>";
	
	tdInfoPanel.innerHTML = strTemp;
}