
var g_xmlHttp = null;

function genericDisplayer( displayElement ) {
	if ( g_xmlHttp.readyState == 4 || g_xmlHttp.readyState == "complete" ) { 
		document.getElementById( displayElement ).innerHTML = g_xmlHttp.responseText;
		g_xmlHttp = null;
	} 
}

function populateFromAjaxAsync( targetURL, displayer, toSend ) {
	if ( !getHttpRequest() ) { return; }
	g_xmlHttp.open( "POST", targetURL, true );
	g_xmlHttp.onreadystatechange = displayer;
	g_xmlHttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
	g_xmlHttp.send( toSend );
}

function populateFromAjaxSync( targetURL, toSend, displayElement ) {
	document.getElementById( displayElement ).innerHTML = doAjaxSync( targetURL, toSend );
}

function doAjaxASync( targetURL, toSend ) {
	if ( !getHttpRequest() ) { return; }
	g_xmlHttp.open( "POST", targetURL, true );
	g_xmlHttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
	g_xmlHttp.send( toSend );
}

function doAjaxSync( targetURL, toSend ) {
	if ( !getHttpRequest() ) { return ""; }
	g_xmlHttp.open( "POST", targetURL, false );
	g_xmlHttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
	g_xmlHttp.send( toSend );
	return g_xmlHttp.responseText;
}

function getHttpRequest() {
	if ( !g_xmlHttp ) {
		if ( window.XMLHttpRequest ) {
			g_xmlHttp = new XMLHttpRequest(); // the rest of the world
		} else if ( window.ActiveXObject ) {
			// m$
			try {
				g_xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP" );
			} catch ( e ) {
				try {
					g_xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );
				} catch ( e ) {}
			}
		}
	}
	if ( !g_xmlHttp ) {
		alert( "Seems your browser cannot create an XMLHttpRequest object. This is no good." );
	}
	return g_xmlHttp;
}