
var	global_AJAX_Array	= new Array();
var	global_AJAX_Count	= 0;

	
function makeNewAjax()
	{
    if( window.XMLHttpRequest ) 
    	{
	   		return new XMLHttpRequest(); 
    	} 
    else 
    	{
	   		return  new ActiveXObject("MSXML2.XMLHTTP");
    	}
	}
function findAjaxIndex()
	{
		var	index;
		for( index = 0; index < global_AJAX_Count; ++index )
			if( null == global_AJAX_Array[index] )
				return index;
		++global_AJAX_Count;
		return index;
	}


function queryForInnerHTML( query, elementId, postQueryFunc, postArgs )
	{
		var	body;
		var	index = findAjaxIndex();
		global_AJAX_Array[index] = makeNewAjax();
				
		body	 = "var ajax = global_AJAX_Array[" + index + "];\n";
		body	+= "if( 4 == ajax.readyState )\n";
		body	+= "{ document.getElementById(\"" + elementId + "\").innerHTML = ajax.responseText;\n";
		if( null != postQueryFunc )
			{
				body += postQueryFunc;
				
				if( null == postArgs )
					body += "();\n";
				else
					body += "(" + postArgs + ");\n"
			}
		body	+= "global_AJAX_Array[" + index + "] = null;\n";
		body	+= " }\n";
		
    global_AJAX_Array[index].onreadystatechange = new Function( body );
    
    global_AJAX_Array[index].open( "GET", query, true );
    global_AJAX_Array[index].send(null);
	}

function postForInnerHTML( url, data, elementId, postQueryFunc, postArgs )
	{
		var	body;
		var	index = findAjaxIndex();
		global_AJAX_Array[index] = makeNewAjax();
				
		body	 = "var ajax = global_AJAX_Array[" + index + "];\n";
		body	+= "if( 4 == ajax.readyState )\n";
		body	+= "{ document.getElementById(\"" + elementId + "\").innerHTML = ajax.responseText;\n";
		if( null != postQueryFunc )
			{
				body += postQueryFunc;
				
				if( null == postArgs )
					body += "();\n";
				else
					body += "(" + postArgs + ");\n"
			}
		body	+= "global_AJAX_Array[" + index + "] = null;\n";
		body	+= " }\n";
		
    global_AJAX_Array[index].onreadystatechange = new Function( body );
    
    global_AJAX_Array[index].open( "POST", url, true );
    global_AJAX_Array[index].setRequestHeader( "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8" );
    global_AJAX_Array[index].send( data );
	}

	
// If you plan on doing anything outside of North America, then you'd better encode the things you pass back and forth
// the escape() method in Javascript is deprecated -- should use encodeURIComponent if available
function encode( uri ) 
	{
    if( encodeURIComponent) 
    	{
        return encodeURIComponent(uri);
    	}

    if( escape ) 
    	{
        return escape(uri);
    	}
	}

function decode( uri ) 
	{
    uri = uri.replace(/\+/g, ' ');

    if( decodeURIComponent ) 
    	{
        return decodeURIComponent(uri);
  	  }

    if( unescape ) 
    	{
        return unescape(uri);
    	}

    return uri;
	}

function queryParameters( array )
	{
		if( null == array )
			return null;
		if( array.length < 1 )
			return null;
		
		var	i;
		var	param		= "";
		
		for( i=0; i < array.length; ++i )
			{
				if( i )
					param += "', '";
				else
					param += "'";
				
				param += array[i];
			}
		param += "'";
		return param;
	}

