/*------------------BROWSER CONFIG.  DO NOT TOUCH ---------------*/
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') { //Mozilla/Safari  :)
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) { //ICE Browser... :P
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

/*---------OK, HERE ARE THE FUNCTIONS-------------*/

//Grabs data asynchronously, then executes the given code.  The variable "response" is the returned data, and is available to the given code. The "sender" variable can be given for use in the code.
function doAjaxGet(url,code,sender) {
	var response = '';
	xmlhttp.open("GET", url,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			response = xmlhttp.responseText;
			eval(code);
		}
	}
	xmlhttp.send(null)
}

//DOES NOT WORK YET
function doAjaxPost(url, query, code) { //need to get this working
	var response = '';
	xmlhttp.open("POST", url,true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			response = xmlhttp.responseText;
			eval(code);
		}
	}
	xmlhttp.send(query)
}

//display an alert box containing helptext for a given topic, from an optional url.  If no url is given, it will use "./manpage.php".  loadingtext can be defined to replace the "Loading..." message
function alertHelpText(topic,sender,url,loadingtext) {
	var otext;
	if (loadingtext==undefined) { loadingtext="Loading..."; }
	if (sender!=undefined) { otext=sender.innerHTML; sender.innerHTML=loadingtext; }
	if (url==undefined) { url="manpage.php?topic="+topic; }
	doAjaxGet(url,"if (sender!=undefined) { sender.innerHTML='Finished.'; } alert(response); if (sender!=undefined) { sender.innerHTML='"+otext+"'; }",sender)
	return false;
}

//returns helptext for a given topic, from an optional url and puts it in the given target element.  If no url is given, it will use "./manpage.php". loadingtext can be defined to replace the "Loading..." message
function insertHelpText(topic,sender,target,url,loadintext) {
	var otext;
	if (loadingtext==undefined) { loadingtext="Loading..."; }
	if (sender!=undefined) { otext=sender.innerHTML; sender.innerHTML=loadingtext; }
	if (url==undefined) { url="manpage.php?topic="+topic; }
	var response = '';
	xmlhttp.open("GET", url,true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			response = xmlhttp.responseText;
			if (sender!=undefined) { sender.innerHTML=otext; }
			document.getElementById(target).innerHTML=response; //if Firefox
			/*@cc_on @*/
			/*@if (@_jscript_version >= 5)
			document.getElementById(target).innerText=response; //innerHTML will work in IE, but it doesn't keep line breaks like it does in Firefox.
			@end @*/
		}
	}
	xmlhttp.send(null);
	return false;
}