

//TODO: add a global variable called NotLoggedInMsgShow, set it to 1 once we have shown the error msg then check to make sure it is 0 before we show any more.

//Use this function to do all your ajax related stuff.<BR>
function ajaxThis(url, callBackFunction, async) {
	NewURL = url + "&randomnumber=" + Math.floor(Math.random()*10000) + Math.floor(Math.random()*3000) + Math.floor(Math.random()*15000);  //prevent browser caching by sending always sending a unique url.
	//alert(NewURL);
	var req = newXMLHttpRequest();    
	// Obtain an XMLHttpRequest instance
	var handlerFunction = getReadyStateHandler(req, callBackFunction);    // Set the handler function to receive callback notifications from the request object
	req.onreadystatechange = handlerFunction;
	req.open('GET', NewURL, async);
	// Third parameter specifies request is asynchronous.
	req.send(null);
}

// Returns a new XMLHttpRequest object, or false if this browser doesn't support it.
function newXMLHttpRequest() {
	var xmlreq = false;
	if (window.XMLHttpRequest) {
		// Create XMLHttpRequest object in non-Microsoft browsers
		xmlreq = new XMLHttpRequest();
	} 
	else if (window.ActiveXObject) {
		// Create XMLHttpRequest via MS ActiveX
		try {
			// Try to create XMLHttpRequest in later versions of Internet Explorer
			xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e1) {
			try {
				// Try version supported by older versions of Internet Explorer
				xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e2) {
				xmlreq = false;
			}
		}
	}
	return xmlreq;
}
				 
/* Returns a function that waits for the specified XMLHttpRequest to complete, then passes its XML response to the given handler function. 
 * req - The XMLHttpRequest whose state is changing 
 * responseXmlHandler - Function to pass the XML response to */ 
function getReadyStateHandler(req, responseXmlHandler) {    
	// Return an anonymous function that listens to the     
	// XMLHttpRequest instance    
	return function () {    
		// If the request's status is "complete"        
		if (req.readyState == 4) {            
			// Check that a successful server response was received             
			if (req.status == 200) {
				// Pass the XML payload of the response to the                 
				// handler function                
				responseXmlHandler(req);            
			}
			else {
				if (req.status == 403) {
					alert('You are no longer logged in.\nPlease close this window and log back in.');	
				}
				else{                
					// An HTTP problem has occurred                
					//alert("HTTP error: "+req.status);                
					if (req.responseText) {
						if (req.responseText.indexOf('ERROR AT') !=-1) {
							alert('There was a problem retrieving data from the server.\n\nDetails for technical support:\n'+req.responseText);
						}
						else {
							alert('There was a problem retrieving data from the server.\n\nError Code: '+req.status);
						}
					}
					else {
						alert('There was a problem retrieving data from the server.\n\nError Code: '+req.status);
					}
				}
			}        
		}    
	}
} 
	
//Returns the node text value 
function GetInnerText (node)
{
	return (node.textContent || node.innerText || node.text) ;
}

function ajaxThis_NoResponse(url, async) {
	NewURL = url + "&randomnumber=" + Math.floor(Math.random()*10000) + Math.floor(Math.random()*3000) + Math.floor(Math.random()*15000);  //prevent browser caching by sending always sending a unique url.
	var req = newXMLHttpRequest();    
	// Obtain an XMLHttpRequest instance
	var handlerFunction = getReadyStateHandler_NoResponse(req);    // Set the handler function to receive callback notifications from the request object
	req.onreadystatechange = handlerFunction;
	req.open('GET', NewURL, async);
	// Third parameter specifies request is asynchronous.
	req.send(null);
}

function getReadyStateHandler_NoResponse(req) {    
	// Return an anonymous function that listens to the XMLHttpRequest instance    
	return function () {    
		//Do nothing.
	}
} 

