function ajaxNew() {
var xmlHttp;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("Your browser does not support AJAX!");
return false;
}
}
}
return xmlHttp;
}
function ajaxHandler(handler,xmlHttp) {
if(xmlHttp.readyState==4) {
handler(xmlHttp.responseText);
}
}
function ajaxGet(handler,url,async,returnXML) {
//NOTE: ASYNCRONOUS GET DOES NOT CURRENTLY WORK.
//Make async and returnXML default to false;
var async = (async == null) ? false : 'async';
var returnXML = (returnXML == null) ? false : 'xml';
//Create a new ajax object.
xmlHttp=ajaxNew();
if (async=='async') {
//Set it to use a handler, which is a function name already created and which is passed ot this function.
xmlHttp.onreadystatechange=ajaxHandler(handler,xmlHttp);
}
//Prepare the request. True means asyncronous (don't wait). Falls means syncronous (wait).
xmlHttp.open("GET",url,async);
//Send the get. xmlHttp.readyState will change to 4 when this is complete and a responce is returned.
xmlHttp.send(null);
if (async!='async') {
//Handle the responce.
handler(xmlHttp.responseText);
}
}
function ajaxGetArray(handler,url,async) {
ajaxGet(handler,url,async,'xml');
}
function ajaxError() {
alert('Server Error. Please try again or report this error to the webmaster.');
return false;
}
function ajaxData(text, tag) {
//The input for this looks like xml, but isn't.
//Tags may not be nested, and other requirements are loose.
//example: datamore data
// ajaxData(field2)=='more data';
if (text.indexOf('<'+tag+'>')==-1) return false;
if (text.indexOf(''+tag+'>')==-1) return false;
var start=text.indexOf('<'+tag+'>')+tag.length+2;
var end=text.indexOf(''+tag+'>');
return text.substring(start,end);
}
function ajaxError(text) {
var err=ajaxData(text, 'error');
if (err!=false) {
alert(err);
return true;
}
return false;
}