//
//	http://momche.net
//	mo@momche.net
//	:: feel free to use it BUT
//	:: if you want to use this code PLEASE send a note
//	:: and please keep this disclaimer intact
//

cRemoteLoader = function()
{
	this.bWorking = false;
	this.hXMLHttp = XMLHTTP.createXmlHttp();
}

cRemoteLoader.createContext = function( hLoader, hHandler )
{
	return function()
	{
		if( hLoader.hXMLHttp.readyState == 4 )
		{
			hHandler.call( hLoader );
			hLoader.bWorking = false;
		}
	}
}

cRemoteLoader.prototype.loadContent = function( sUrl, hHandler ) 
{
	if( sUrl )
	{
		this.bWorking = true;
		this.abortLoading();
		//protect against IE caching
		var hNow = new Date();
		if( sUrl.indexOf( '?' ) >= 0 )
		{
			sUrl = sUrl + '&antiiecache='+hNow.getTime();
		}
		else
		{
			sUrl = sUrl + '?antiiecache='+hNow.getTime();
		}
		
		this.hXMLHttp.open( 'GET', sUrl, true );
		this.hXMLHttp.onreadystatechange = cRemoteLoader.createContext( this, hHandler );
		this.hXMLHttp.send( null );
	}
}

cRemoteLoader.prototype.abortLoading = function() 
{
	if( this.bWorking )
	{
		this.hXMLHttp.abort();
	}
}

