/*  Asynchronous vs. Synchronous Execution
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Synchronous program execution: 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Your program is executed line by line, one line at a time. Each time a function is called, 
    program execution waits until that function returns before continuing to the next line of code. 
    This method of execution can have undesirable ramifications. Suppose a function is called to start a time consuming process. 
    What if you want to stop the lengthy process? 
    With synchronous execution, your program is “stuck,” waiting for the process to end, with no way out.
    Synchronous requests may temporarily lock the browser, disabling any actions while the request is active.
    ASynchronous program execution: 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Asynchronous execution avoids this bottleneck. 
    You are essentially saying, 
    “I know this function call is going to take a great deal of time, but my program doesn’t want to wait around while it executes.”
    Ex:
    ~~
    Using asynchronous execution, the TakePicture() function returns immediately and shows the message. 
    Although the two-minute process is not complete, your program can continue to execute. 
    In this manner, your program could set the notCancelledByUser variable to FALSE to cancel the picture. 
    It can also poll or ask the TakePicture() function when the exposure is completed, or if an error occurred during the process.
*/
function makeAjaxRequest(url,callback,bAsynchronous)
{
    bAsynchronous = typeof(bAsynchronous) != 'undefined' ? ((bAsynchronous == false)?false:true) : true;
    //alert('yes');
	if (window.XMLHttpRequest)
	{
		var http_request = new XMLHttpRequest();
		//http_request = null;
	}
	else
	{
		if (window.ActiveXObject)
		{
			var http_request = new ActiveXObject("Microsoft.XMLHTTP");
			//http_request = null;
		}
	}
	http_request.onreadystatechange = function()
	{
		if (http_request.readyState == 4)
		{
			if (http_request.responseXML != null)
			{ 
			    var sFunc;
				sFunc= callback.replace("XML_OBJECT","http_request.responseXML");
				//alert(sFunc);
				eval(sFunc);
			}
		}
	}
	var timestamp = new Date();
    var uniqueURL = url+ (url.indexOf("?") > 0 ? "&" : "?") + "timestamp="+ timestamp.getTime();

	http_request.open("GET",uniqueURL,bAsynchronous);
	http_request.send("");
}

function getNode(obj,pos)
{
	if (window.XMLHttpRequest)
		return obj[pos];
	else
		return obj.item(pos);
}

function getSingleNode(obj,tagName)
{
	if (window.XMLHttpRequest)
	{
	    if (getRawNode(obj,tagName).selectSingleNode("text()")!=null)
		    return getRawNode(obj,tagName).selectSingleNode("text()").nodeValue;
		else
		    return null;
	}
	else
	    if (getRawNode(obj,tagName)!=null)
		    return getRawNode(obj,tagName).text;
	    else
	        return null;
}
function getSingleNodeByPosition(obj,pos) 
{
	if (window.XMLHttpRequest)
		return obj[pos];
	else
		return obj.item(pos);
}

function getRawNode(obj,tagName)
{
	return obj.selectSingleNode(tagName);
}

function getAttribute(obj,attName)
{
	if (window.XMLHttpRequest)
		return obj.selectSingleNode("@" + attName).nodeValue;
	else
		return obj.getAttribute(attName);
}
