var m_iCurrAjaxId = 1;
function makeRequestThreaded(strURL, sAction) {
	if ( strURL.indexOf('?') > 0 ) {
		strURL += "&ajaxid="+m_iCurrAjaxId;
	} else {
		strURL += "?ajaxid="+m_iCurrAjaxId;
	}
	//var	url='ajax_threads_server.php?delay='+parseInt(document.getElementById('delay_text').value)+"&ajaxid="+m_iCurrAjaxId;
	var log_string = "<br /><strong>Making an HTTPRequest</strong><br />\n&nbsp;&nbsp;&nbsp;Param: "+m_iCurrAjaxId+"<br />\n&nbsp;&nbsp;&nbsp;URL: "+strURL;
	var	eDate = new Date();
	var index = MakeNewAJAXCall(strURL, SimpleCallback, 'GET', ComplexCallback, m_iCurrAjaxId, eDate.getTime(), sAction);
	log_string += "<br />\n&nbsp;&nbsp;&nbsp;Index: "+index+"\n"
	MakeLogEntry(log_string);
}
/*****************************************************************
	This is the "simple" callback that is made at the completion of
	the HTTPRequest.

	Parameters:
		in_text:		The request result text.
		in_param:	This is the first of the two "extra" parameters
						that were supplied when the call was made.
		in_param2:	This is the second of the two parameters.
*/
function SimpleCallback(in_text, in_param, in_param2, gui_callback){
	var	eDate = new Date();
	var time_spent = parseInt ((eDate.getTime() - in_param2) / 100) / 10;

	//alert(gui_callback);
	eval(gui_callback+'(in_text);');

	var log_string = "<strong>Simple Callback ("+gui_callback+")</strong><br />\n&nbsp;&nbsp;&nbsp;Response: '"+in_text+"'<br />\n&nbsp;&nbsp;&nbsp;Param: '"+in_param+"'<br />\n&nbsp;&nbsp;&nbsp;This request took "+time_spent+" seconds to complete.";
	MakeLogEntry(log_string);
}

/*****************************************************************
	This is the "complex" callback. It is called for every stage
	of the request.
	
	For Stage 4 (complete), this callback is called prior to the
	"simple" callback.
	
	Parameters:
		in_stage:	This is the request stage (0-4)
		in_text:		The request result text.
		in_param:	This is the first of the two "extra" parameters
						that were supplied when the call was made.
		in_param2:	This is the second of the two parameters.
		in_index:	This is the index of the request. This can be
						used to directly index the request array.
*/
function ComplexCallback(in_stage, in_text, in_param, in_param2, in_index){
	var	eDate = new Date();
	var time_spent = parseInt ((eDate.getTime() - in_param2) / 100) / 10;
	var log_string = "<strong>Complex Callback</strong><br />\n&nbsp;&nbsp;&nbsp;Index: "+in_index+"<br />\n&nbsp;&nbsp;&nbsp;Stage: "+in_stage+"<br />\n&nbsp;&nbsp;&nbsp;Response: '"+in_text+"'<br />\n&nbsp;&nbsp;&nbsp;Param: '"+in_param+"'<br />\n&nbsp;&nbsp;&nbsp;This request took "+time_spent+" seconds to get to this point.";
	MakeLogEntry(log_string);
}

/*****************************************************************
	This simply displays the given text in the log. It checks to
	see if there is supposed to be a displayed log. If not, then
	nothing happens. If this is the first entry, then a header is
	displayed.
	
	Parameters:
		in_text:	The text to be displayed (raw HTML)
*/
function MakeLogEntry ( in_text ){
	if ( document.getElementById('divAjaxLog') ){
		var old_val = document.getElementById('divAjaxLog').innerHTML;
		var newval;
		if (!old_val)	{ newval = '<hr /><h3 style="margin:0;padding:0">Event Log</h3>'+"\n"+in_text; }
		else			{ newval = old_val+"<br />\n"+in_text; }
		document.getElementById('divAjaxLog').style.display = 'none'; 
		document.getElementById('divAjaxLog').innerHTML = newval;
		document.getElementById('divAjaxLog').style.display = 'block'; 
	}
}

/*****************************************************************
	The main reason for this is to clear the log.
*/
function SetLog(){
	if( document.getElementById('divAjaxLog') ){
		// This forces IE to flush its cache.
		document.getElementById('divAjaxLog').style.display = 'none';
		document.getElementById('divAjaxLog').innerHTML = '';
		document.getElementById('divAjaxLog').style.display = 'block';
	}
}
