/*
Filename: 	ajax.js
Date:		30/09/2007
Last Edited By: Andrew Cohen
Purpose:  This page has all the javascript needed for the AJAX
*/

var xmlHttp;
var IE = document.all?true:false;

var popupBoxTimer = null;
var coordX;
var coordY;

function displayAttrInfo(e,str)
{
	if (popupBoxTimer)
	{
		clearTimeout(popupBoxTimer);
		popupBoxTimer = null;
	}
	if (IE)
	{	coordX = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		coordY = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;}
	else
	{	coordX = e.pageX;
		coordY = e.pageY;}
	popupBoxTimer = setTimeout(function(){displayAttrInfoMain(str)}, 400);
}

function displayAttrInfoMain(str)
{
	popupBoxTimer = null;
	
	var t = document.getElementById("helpbox");
	t.innerHTML = "<table class='dhpopup' border='0'><tr><td class='dhpopuptext'>Loading...</td></tr></table>";
	
	//offset to stop it going off the side of the page
	if (coordX-310 < 10)
	{t.style.left = coordX+10+"px";}
	else
	{t.style.left = coordX-310+"px";}
	
	t.style.top = coordY+15+"px";
	t.style.visibility = 'visible';	

	xmlHttp=new GetXmlHttpObject();
	var url=str+"&sid="+Math.random();
	xmlHttp.onreadystatechange=returnAjaxInfo;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function loadMaintenance()
{
	xmlHttp=new GetXmlHttpObject();
	var url="/includes/maintenance.php?type=onload";
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function returnAjaxInfo() 
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("helpbox").innerHTML="<table " + 
		"class='dhpopup' border='0'><tr><td class='dhpopuptext'>" +xmlHttp.responseText + "</td></tr></table>";
	}
}

function removeAjaxInfo() 
{
	document.getElementById("helpbox").style.visibility = "hidden";
	clearTimeout(popupBoxTimer);
}

var xmlMessagePrefix = "<p class=\"error\">"
var xmlMessageSuffix = "</p>"

function GetXmlHttpObject()
{ 
	var objXMLHttp = null;
	if (window.XMLHttpRequest)
	{
		objXMLHttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (objXMLHttp === null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	} 
	return objXMLHttp;
}

function xmlHttpResponse(messageID,messageContent,displayID) 
{
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")
	{
		document.getElementById(messageID).innerHTML = messageContent;
		document.getElementById(displayID).innerHTML = xmlHttp.responseText;
	}
}

function clearMessageDisplayBox() 
{
	document.getElementById('messageDisplayBox').innerHTML = "";
}

var historyTablePresent = 0;

function toggleHistory(boardID)
{
	moveHis = document.getElementById("moveHistory").style
	if (historyTablePresent == 0)
	{
		document.getElementById("moveHistory").innerHTML="Loading...";
		xmlHttp=new GetXmlHttpObject();
		var url='/includes/functions/ajax/historytable.php?boardID='+boardID+"&sid="+Math.random();
		xmlHttp.onreadystatechange=fillHistoryBox;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	if (moveHis.display == 'none')
	{
		moveHis.display = 'inline';
		document.getElementById("linkmoveHistory").innerHTML = 'Hide Move History';
	}
	else 
	{
		moveHis.display = 'none';
		document.getElementById("linkmoveHistory").innerHTML = 'Show Move History';
	}
}

function fillHistoryBox() 
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("moveHistory").innerHTML=xmlHttp.responseText;
		historyTablePresent = 1
	}
}

function displaySiteReport(e,pageURL)
{
	var t = document.getElementById("reportOutput");
	t.innerHTML = "Loading...";
	 
	xmlHttp=new GetXmlHttpObject();
	var url=pageURL+'sid='+Math.random();
	xmlHttp.onreadystatechange=showSiteReport;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function showSiteReport() 
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("reportOutput").innerHTML=xmlHttp.responseText;
	}
}

var kibitzComment;

function postKibitzComment(boardID)
{
	kibitzComment = escape(document.getElementById('titleMatchKibitz').value);
	document.getElementById('kibitzError').innerHTML = "[Please Wait...]<br /><br />";
	document.getElementById('titleMatchKibitz').value = "";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/functions/ajax/kibitz_postcomment.php?boardID="+boardID+"&kibitzComment="+
		kibitzComment+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('kibitzError',''+
		'','matchKibitzContent');}; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

// -->
