var _xmlObjs = new Array();			// Array of XmlHttpRequestsvar _xmlArgs = new Array();			// Array for keeping all parameters of the custom call backvar _index = -1;							// Current XmlHttpRequest index/** * Calls AJAX for a given URL, and provides the corresponding callback for reacting. */function tbAJAX(url,callback) {	_index++;	if(window.XMLHttpRequest) {		_xmlObjs[_index]=new XMLHttpRequest()	} else if (window.ActiveXObject) {		_xmlObjs[_index]=new ActiveXObject("Microsoft.XMLHTTP")	}	// Getting arguments for the custom call back (localArgs[0] contains the  callback function)	var localArgs = new Array();	for(var i=1; i<arguments.length; i++)		localArgs[i-1] = arguments[i];	_xmlArgs[_index] = localArgs;	// Store the callback arguments	// The real callback is a simple transient function, that allows for passing parameters, something we were missing	_xmlObjs[_index].onreadystatechange = new Function("transientChangeState","_changeState(_xmlObjs["+_index+"],_xmlArgs["+_index+"]);");	_xmlObjs[_index].open("GET",url,true);	_xmlObjs[_index].send(null);}function tbAJAX_post(url,parameters,callback) {	_index++;	if(window.XMLHttpRequest) {		_xmlObjs[_index]=new XMLHttpRequest()	} else if (window.ActiveXObject) {		_xmlObjs[_index]=new ActiveXObject("Microsoft.XMLHTTP")	}	// Getting arguments for the custom call back (localArgs[0] contains the  callback function)	var localArgs = new Array();	for(var i=1; i<arguments.length; i++)		localArgs[i-2] = arguments[i];	_xmlArgs[_index] = localArgs;	// Store the callback arguments		// Computing POST parameters	var paramstr = "";	if(parameters != null)		for(i in parameters)			paramstr += "&"+i+"="+encodeURI(parameters[i]);				paramstr = paramstr.substr(1); // Removes the leading ampersand		// The real callback is a simple transient function, that allows for passing parameters, something we were missing	_xmlObjs[_index].onreadystatechange = new Function("transientChangeState","_changeState(_xmlObjs["+_index+"],_xmlArgs["+_index+"]);");	_xmlObjs[_index].open("POST",url,true);	_xmlObjs[_index].setRequestHeader("Content-type", "application/x-www-form-urlencoded");	_xmlObjs[_index].setRequestHeader("Content-length", paramstr.length);	_xmlObjs[_index].setRequestHeader("Connection", "close");	_xmlObjs[_index].send(paramstr);}/** * The generic callback. Calls the custom callback with its corresponding parameters. * The first parameter passed to the callback is the XmlHttpRequest object itself, used for getting the data back. */function _changeState(xmlObj,args) { 	if(xmlObj.readyState==4 || xmlObj.readyState=="complete") { 			// Constructs the list of arguments		var argslist = "";		for(var i=1; i<args.length; i++)			argslist += "args["+i+"],";		if(args.length > 1)			argslist = ","+argslist+"args["+(args.length-1)+"]";		// Calls the callback function, with all its arguments.		eval("args[0](xmlObj"+argslist+")");	}}/** * Callback function for tbAJAX. Loads an HTML snippet in the given layer (id of a container tag). * This function takes care of loading JavaScripts! (However functions with declarations not on a single line may be omitted). */function tbAJAXLoad(xmlObj,layer) {	document.getElementById(layer).innerHTML = xmlObj.responseText;	// Scripts are not evaluated... make sure it's executed	var scripts = document.getElementById(layer).getElementsByTagName("script");	// Whenever scripts are executed, functions get "forgotten". Assigning functions as members of	// the window object make them survive...	for(i = 0; i<scripts.length; i++) {		var s = scripts[i].innerHTML;		var res = s.match(/function [^(]+\(/g);		for(j = 0; j<res.length; j++) {			var funcName = res[j].replace(/(function\W+)|(\W*\()/g,"");	// Isolates the function name			s += "\nwindow."+funcName+" = "+funcName;		}        		eval(s);	}}/** * Shows a window containing the HTML code of the current document, with AJAX loaded HTML code in place. */function tbAJAXShowDebugWindow() {	var dbg = window.open('about:blank','_DEBUG_','dependent=yes,width=1024,height=768,location=no,menubar=no,status=no,toolbar=no,scrollbars=yes');	var html = document.getElementsByTagName('html')[0].outerHTML;	if(html == null)	// Firefox does not bring anything for <html>.outerHTML...		html = '<html>\n'+document.getElementsByTagName('html')[0].innerHTML+'\n</html>';	html = html.replace(/&/g,'&amp;');	html = html.replace(/</g,'&lt;');	html = html.replace(/>/g,'&gt;');		// Line counter	var index = 0;	html = html.replace(/^|\n/g,function (str) { return '\n'+(++index)+':\t'; } );	// Writing contents in the window		dbg.document.open();	dbg.document.writeln('</html>');	dbg.document.writeln('<head><title>tbAJAX Debug Window</title></head>');	dbg.document.writeln('<body><h2>tbAJAX Debug Window</h2><pre>'+html+'</pre></body></html>');	dbg.document.close();}/** * Function used to replace the URL of the active page when called through frmRelocator * Needs String management JS Library to be included to work */function GotoURL( stLink, stDb ) {	stHref = document.location.href;	stHref = replaceSubstring(stHref, Sleft( Sright( stHref , '&Element='), '&' ), stLink);	if(stDb != null){		stHref = replaceSubstring(stHref, Sleft( Sright( stHref , '&Database='), '&' ), stDb);	}	document.location.href = stHref;}
