var xmlreqs = new Array(); 

function XMLReq()
{
	this.xmlHttp = GetXmlHttpObject();
	this.xmlHttp = this.xmlHttp == null ? false : this.xmlHttp;
}

function performAjaxJob( url, parameters )
{	
	var pos = -1; 

	if ( pos == -1 ) 
	{ 
		pos = xmlreqs.length; 
		xmlreqs[ pos ] = new XMLReq(); 
	} 
	xmlreqs[ pos ].xmlHttp = GetXmlHttpObject();
	if ( xmlreqs[ pos ].xmlHttp ) // browser does support AJAX
	{
		var method = parameters == "" ? "GET" : "POST";
		
		xmlreqs[ pos ].xmlHttp.onreadystatechange = function()
		{
			stateChanged( pos );	
		}
		xmlreqs[ pos ].xmlHttp.open( method, url, true );
		if ( method == "POST" )
		{
			xmlreqs[ pos ].xmlHttp.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
			xmlreqs[ pos ].xmlHttp.setRequestHeader( "Content-length", parameters.length );
			xmlreqs[ pos ].xmlHttp.setRequestHeader( "Connection", "close" );
		}
		xmlreqs[ pos ].xmlHttp.send( parameters == "" ? null : parameters );
	}
}

function stateChanged( pos ) 
{ 
	if ( xmlreqs[ pos ].xmlHttp.readyState == 4 )
	{ 
	    // do nothing
	}
}

function GetXmlHttpObject()
{
    var xmlHttp = null;
    
	try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
		try
		{
			xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP" );
		}
		catch (e)
		{
			xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );
		}
  	}
	return xmlHttp;
}

