function ajaxLoader(url, destid, waitid, waitText, method, doonceloaded){	if (!url || url==""){		alert("Missing url");		return false;		}					if  (!destid || destid==""){		alert("Missing destination div id");		return false;		}					this.url=url;	this.destid=destid;	this.waitid=(!waitid || waitid=="") ? destid: waitid ;	waitid=(!waitid || waitid=="") ? destid: waitid ;	this.waitel=document.getElementById(this.waitid);	//alert("'" + waitText + "'");	//this.waitText=(!waitText) ? "Wait please, connecting..." : waitText ;	this.method = (method && method!="") ? method : "GET";		this.doonceloaded=(doonceloaded)?doonceloaded:"";		this.req = null;		this.startRequest=startRequest;	this.ajaxRequest=ajaxRequest;	this.onChangeState=onChangeState;	this.extractAndDo=extractAndDo;		function startRequest(){		with (this){			try {							if (waitid!=destid)					waitel.style.display="block";				if (waitText && waitText!="")					waitel.innerHTML=waitText;									if (url.indexOf("destboxid=")<0)					url += ((url.indexOf("?")>0) ? "&" : "?") + "destboxid=" + this.destid;									//url += ((url.indexOf("?")>0) ? "&" : "?") + 'rnd=' + Math.floor(Math.random() * 100);								ajaxRequest(url, method);				}			catch(tError) {				alert( tError.name + ": " + tError.message + "(startRequest)");				}			 }		}			function ajaxRequest(theUrl, theMode) {		try{			// branch for native XMLHttpRequest object			var tMode= theMode ? theMode : 'GET';			var tParams="";						if (tMode=="POST"){				var tArray=theUrl.split("?")				if (tArray.length>1)					tParams=tArray[1];				}							if (window.XMLHttpRequest) {				req = new XMLHttpRequest();				req.onreadystatechange = onChangeState;				req.open(tMode, theUrl, true);				req.setRequestHeader('If-Modified-Since', 'Wed, 15 Nov 1995 00:00:00 GMT');				if (tMode=="POST")					req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');				if (tParams=="")					req.send(null);				else					req.send(tParams);				// branch for IE/Windows ActiveX version				} 			else if (window.ActiveXObject) {				isIE = true;				req = new ActiveXObject("Microsoft.XMLHTTP");				//alert(req);				if (req) {					req.onreadystatechange = onChangeState;					req.open(tMode, theUrl, true);					if (tMode=="POST")						req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');					if (tParams=="")						req.send();					else						req.send(tParams);					}				}			}		catch(tError) {			alert( tError.name + ": " + tError.message + "(ajaxRequest)");			}		}					function onChangeState() {		// only if req shows "loaded"		//alert(req.readyState);		try{			switch (req.readyState)				{				case 1:				case 2:				case 3:					{						break;						}				case 4:					{						try							{								// only if "OK"								if (req.status == 200) {									var tInnerText=req.responseText									try{										tInnerText=extractAndDo(tInnerText);										}									catch(tEvalErr){										tInnerText=tInnerText+"<!--" + tEvalErr.name + ": " + tEvalErr.message + "-->"										}									document.getElementById(destid).innerHTML=tInnerText;									//buildTopicList();									} 								else {									document.getElementById(destid).innerHTML = "There was a problem retrieving the XML data:\n" + req.statusText ;									}								if (destid != waitid)									document.getElementById(waitid).style.display="none";								break;								}						catch(tError)							{								document.getElementById(destid).innerHTML="<b>" + tError.name + "</b>: " + tError.message;								}						if (doonceloaded && doonceloaded!="")							alert(doonceloaded);						}				}			}		catch(tError) {			alert( tError.name + ": " + tError.message + "(onChangeState)");			}		}			function extractAndDo(theText) {		try{			var reg = /<!--#(.|\n)+?#-->/gi;			var corr = theText.search(reg);			//alert(corr);			if(corr != -1) {				var exprf = theText.match(reg);				for(var i = 0; i < exprf.length; i++) {					var com = exprf[i].substring(5, exprf[i].length - 4);					//alert(com);					eval(com);					}				}			return theText.replace(reg, '');			}		catch(tError) {			alert( tError.name + ": " + tError.message + "[extractAndDo: " + theText + "]");			}		}	}		function ajaxLoadXsl(siteUrl, data, struct, num, destid, waitid, waitText, args){	var tUrl=siteUrl + "public/ajax/responder?action=getxsl&data=" + data + "&struct=" + struct + "&num=" + num + "&args=" + ((args)?args:"");	var tLoader=new ajaxLoader(tUrl, destid, waitid, waitText);	tLoader.startRequest(); 	}	//===========OLD CODE; REFACTORED ABOVE================////var req;//var waitel;//var destel;function launchRequest(theUrl, theDestBox, theWaitBox, theWaitText, theMethod){	try {			if (!theUrl ||theUrl==""){			alert("Missing url");			return false;			}								if  (!theDestBox || theDestBox==""){			alert("Missing destination div id");			return false;			}								var tWaitId = (theWaitBox && theWaitBox!="") ? theWaitBox : theDestBox;		var tWaitText = (theWaitText && theWaitText!="") ? theWaitText : "Wait please, connecting...";		var tUrl=theUrl;				var tMethod = (theMethod && theMethod!="") ? theMethod : "GET";				var tWaitElem = document.getElementById(tWaitId);		var tDestElem = document.getElementById(theDestBox);				if (tWaitId!=theDestBox)			tWaitElem.style.display="block";		tWaitElem.innerHTML=tWaitText;				if (tUrl.indexOf("destboxid=")<0)			tUrl += ((tUrl.indexOf("?")>0) ? "&" : "?") + "destboxid=" + theDestBox;					//alert(tUrl);		//tWaitElem.innerHTML=tUrl;				ajaxLoad(tUrl, tMethod, tWaitElem, tDestElem)		}	catch(tError) {		alert( tError.name + ": " + tError.message + "(launchRequest)");		}	}			function ajaxLoad(url, theMode, theWaitElem, theDestElem) {	// branch for native XMLHttpRequest object	var tMode= theMode ? theMode : 'GET';	var tParams=""		if (tMode=="POST"){		var tArray=url.split("?")		if (tArray.length>1)			tParams=tArray[1];		}			if (window.XMLHttpRequest) {		req = new XMLHttpRequest();		waitel=theWaitElem;		destel=theDestElem;		req.onreadystatechange = reqChange;		req.open(tMode, url, true);		req.setRequestHeader('If-Modified-Since', 'Wed, 15 Nov 1995 00:00:00 GMT');		if (tMode=="POST")			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');		if (tParams=="")			req.send(null);		else			req.send(tParams);		// branch for IE/Windows ActiveX version		} 	else if (window.ActiveXObject) {		isIE = true;		req = new ActiveXObject("Microsoft.XMLHTTP");		if (req) {			req.onreadystatechange = reqChange;			req.open(tMode, url, true);			waitel=theWaitElem;			destel=theDestElem;			if (tMode=="POST")				req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');			if (tParams=="")				req.send();			else				req.send(tParams);			}		}	}			function reqChange() {	// only if req shows "loaded"	switch (req.readyState)		{		case 1:		case 2:		case 3:			{				break;				}		case 4:			{				try					{						// only if "OK"						if (req.status == 200) {							var tInnerText=req.responseText							try{								tInnerText=executeCommands(tInnerText);								}							catch(tEvalErr){								tInnerText=tInnerText+"<!--" + tEvalErr.name + ": " + tEvalErr.message + "-->"								}							destel.innerHTML=tInnerText;							//buildTopicList();							} 						else {							destel.innerHTML = "There was a problem retrieving the XML data:\n" + req.statusText ;							}						if (destel != waitel)							waitel.style.display="none";						break;						}				catch(tError)					{						destel.innerHTML="<b>" + tError.name + "</b>: " + tError.message;						}				}		}	}				function executeCommands(mytext) {	try{		var reg = /<!--#(.|\n)+?#-->/gi;		var corr = mytext.search(reg);		//alert(corr);		if(corr != -1) {			var exprf = mytext.match(reg);			for(var i = 0; i < exprf.length; i++) {				var com = exprf[i].substring(5, exprf[i].length - 4);				//alert(com);				eval(com);				}			}		return mytext.replace(reg, '');		}	catch(tError) {		alert( tError.name + ": " + tError.message + "[executeCommands: " + mytext + "]");		}	}
