function setupAJAXRequest(reqLoc,reqPar)
{
	var XMLRequest = false;
	if(window.XMLHttpRequest){XMLRequest = new XMLHttpRequest();}
	else if(window.ActiveXObject){
		XMLRequest = new ActiveXObject("Msxml2.XMLHTTP");
		if(! XMLRequest){XMLRequest = new ActiveXObject("Microsoft.XMLHTTP");}}
	else if(window.createRequest){XMLRequest = window.createRequest;}
	if(! XMLRequest){alert("Your browser does not support XML HTTP Requests. Please update or change to a browser able to perform this action.");return false;}
	else{
		XMLRequest.open("POST","/" + reqLoc,true);
		XMLRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		XMLRequest.setRequestHeader("Content-length",reqPar.length);
		XMLRequest.setRequestHeader("Connection","close");
		return XMLRequest;}
}

function urlencode(str)
{
	var encStr = escape(str);
	while(encStr.match(/\+/))
		encStr = encStr.replace('+','%2B');
	
	while(encStr.match(/\%20/))
		encStr = encStr.replace('%20','+');
	
	while(encStr.match(/\@/))
		encStr = encStr.replace('@','%40');
	
	while(encStr.match(/\&/))
		encStr = encStr.replace('&','%26');

	return encStr;
}

function xmlObject(responseObj)
{
	try
	{
		// This handles the XML parsing in Internet Explorer
		retXMLObj=new ActiveXObject("Microsoft.XMLDOM");
		retXMLObj.async="false";
		retXMLObj.loadXML(responseObj);
		return retXMLObj;
	}
	catch(e)
	{
		try
		{
			// This handles the XML parsing in most other browsers (eg. FireFox, Opera, etc.)
			parser=new DOMParser();
			return parser.parseFromString(responseObj,"text/xml");
		}
		catch(e)
		{
			return;
		}
	}
}

function DimBackground(zIndex)
{
	if(! document.getElementById('BackgroundDimDIV'))
	{
		var backgroundDimObj = document.createElement("div");
		backgroundDimObj.id = "BackgroundDimDIV";
		backgroundDimObj.style.height = getPageDims().pageHeight + "px";
		document.getElementsByTagName("body")[0].appendChild(backgroundDimObj);
	}
	document.getElementById('BackgroundDimDIV').style.zIndex = zIndex;
	document.getElementById('BackgroundDimDIV').style.visibility="visible";
	document.getElementById('BackgroundDimDIV').style.display="block";
	setOpacity('BackgroundDimDIV',0.6);
}

function UnDimBackground()
{
	if(document.getElementById('BackgroundDimDIV'))
		document.getElementsByTagName("body")[0].removeChild(document.getElementById('BackgroundDimDIV'));
}

function setOpacity(objectID,opacity)
{
	var obj = document.getElementById(objectID);
	if(opacity > 0 && obj.style.visibility != "visible")
		obj.style.visibility="visible";

	obj.style.opacity = opacity;
	obj.style.filter = "alpha(opacity=" + opacity * 100 + ")"; 
}

function getPageDims()
{
	var pageHeight, pageWidth;

	if(window.innerHeight && window.scrollMaxY)
	{
		pageHeight = window.innerHeight + window.scrollMaxY;
		pageWidth = window.innerWidth + window.scrollMaxX;
	}
	else if(document.body.scrollHeight > document.body.offsetHeight)
	{
		pageHeight = document.body.scrollHeight;
		pageWidth = document.body.scrollWidth;
	}
	else
	{
		pageHeight = document.body.offsetHeight;
		pageWidth = document.body.offsetWidth;
  	}

	var winHeight, winWidth;

	if (self.innerHeight)
	{
		winWidth = self.innerWidth;
		winHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		winWidth = document.documentElement.clientWidth;
		winHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		winWidth = document.body.clientWidth;
		winHeight = document.body.clientHeight;
	}	

	if(pageHeight < winHeight)
		pageHeight = winHeight;
	if(pageWidth < winWidth)
		pageWidth = winWidth;

	var xScroll, yScroll;

	if(self.pageYOffset)
	{
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	}
	else if(document.documentElement && document.documentElement.scrollTop)
	{
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	}
	else if(document.body)
	{
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}

	return {pageHeight:pageHeight, pageWidth:pageWidth, winHeight:winHeight, winWidth:winWidth, yScroll:yScroll, xScroll:xScroll};
}

function dialogBox()
{
	DimBackground('35');
	var dialogHeader = arguments[0];
	var dialogText = arguments[1];

	var dialogBoxObj = document.createElement("div");
	dialogBoxObj.className = "DialogBox";
	dialogBoxObj.style.visibility="visible";
	dialogBoxObj.style.display="block";
	dialogBoxObj.style.position="absolute";
	
	document.getElementsByTagName("body")[0].appendChild(dialogBoxObj);
	
	var dialogHeaderObj = document.createElement("h1");
	dialogHeaderObj.appendChild(document.createTextNode(dialogHeader));
	
	dialogBoxObj.appendChild(dialogHeaderObj);
	var dialogBoxTextContainer = document.createElement("div");
	dialogBoxTextContainer.innerHTML = dialogText;
	dialogBoxObj.appendChild(dialogBoxTextContainer);
	
	var dialogBoxButtonContainerObj = document.createElement("div");
	dialogBoxObj.appendChild(dialogBoxButtonContainerObj);
	
	var buttonDivWidth = 0;
	
	for(var i=2; i < arguments.length; i=i+2)
	{
		var dialogBoxButtonObj = document.createElement("div");
		dialogBoxButtonObj.className="buttonItem";
		dialogBoxButtonObj.style.margin="3px";
		dialogBoxButtonObj.style.cssFloat="left";
		dialogBoxButtonObj.style.styleFloat="left";
		dialogBoxButtonObj.appendChild(document.createTextNode(arguments[i]));

		if(arguments[i+1])
			dialogBoxButtonObj.onclick=arguments[i+1];
		else
			dialogBoxButtonObj.onclick=function(){UnDimBackground();};

		if(dialogBoxButtonObj.addEventListener)
			dialogBoxButtonObj.addEventListener("click",function(){hideDialogBox(dialogBoxObj);},false);
		else if(dialogBoxButtonObj.attachEvent)
			dialogBoxButtonObj.attachEvent("onclick",function(){hideDialogBox(dialogBoxObj);});

		dialogBoxButtonContainerObj.appendChild(dialogBoxButtonObj);
		buttonDivWidth += (dialogBoxButtonObj.offsetWidth + 8);
	}
	
	dialogBoxButtonContainerObj.style.position="relative";
	dialogBoxButtonContainerObj.style.left="50%";
	dialogBoxButtonContainerObj.style.width=buttonDivWidth + "px";
	dialogBoxButtonContainerObj.style.marginLeft = (parseInt(buttonDivWidth / 2) + 20) * -1 + "px";
	dialogBoxButtonContainerObj.style.marginTop="10px";
}

function hideDialogBox(dialogBoxObj)
{
	xRemoveNode(dialogBoxObj,true);	
}

function xRemoveNode(nodeObj,boolRemoveSelf)
{
	// This is my own form of DOM node removing - it goes through and removes all child elements along with the node itself (if boolRemoveSelf is true)
	if(nodeObj.hasChildNodes())
	{
		while(nodeObj.childNodes.length > 0)
			xRemoveNode(nodeObj.firstChild,true);
	}

	if(boolRemoveSelf)
		nodeObj.parentNode.removeChild(nodeObj);
}