var jaRequest = function ( pCallback, url, auto_run, sender, method, post_params ) {
	this.hReq = null;
	this.hTimeout = null;
	this.pCallback = pCallback;
	this.url = url;
	this.auto_run = auto_run;
	this.sender = sender;
	this.method = method;
	this.post_params = post_params;

	this.initialize = function ( ) {
		this.hReq = null;

		if ( window.XMLHttpRequest ) {
			try {
				this.hReq = new XMLHttpRequest ( );
			} catch ( e ) { }
		} else if ( window.ActiveXObject ) {
			try {
				this.hReq = new ActiveXObject ( 'Msxml2.XMLHTTP' );
			} catch ( e ) {
				try {
					this.hReq = new ActiveXObject ( 'Microsoft.XMLHTTP' );
				} catch ( e ) { }
			}
		}
	},

	this.processOk = function ( ) {
		if ( this )	return pCallback ( this, eval ( this.hReq.getResponseHeader ( 'X-JSON' ) ) );
	},

	this.query = function ( url ) {
		if ( !this.hReq ) return false;

		var p = this;

		this.hReq.onreadystatechange = function ( ) {
			if ( p.hReq.readyState == 4 ) {
				clearTimeout ( p.hTimeout );

				if ( p.hReq.status == 200 ) {
					p.processOk ( );
				}
			}
		}

		this.hReq.open ( this.method, url, true );
		this.hReq.setRequestHeader ( 'If-Modified-Since', 'Mon, 12 Nov 1984 18:45:00 GMT' );
		if ( this.method == 'POST' ) {
			var params = '';
			
			if ( typeof ( this.post_params ) == 'object' ) {
				params = object_toPostDataIn ( this.post_params );
			}
		
			this.hReq.setRequestHeader ( "Content-type", "application/x-www-form-urlencoded" );
//			this.hReq.setRequestHeader ( "Content-length", params.length );
//			this.hReq.setRequestHeader ( "Connection", "close" );
			this.hReq.send ( params );
		} else {
			this.hReq.send ( null );
		}
		this.hTimeout = setTimeout ( function ( ) { p.hReq.abort ( ); }, 10000 );
	}

	this.initialize ( );

	if ( this.auto_run ) this.query ( this.url );
}

function	loadJaContentPost ( container, url, params ) {
	new jaRequest ( function ( h, a ) { container.innerHTML = h.hReq.responseText; }, url, true, null, 'POST', params );
}

function	evalAjaxContent ( url ) {
	new jaRequest ( function ( h, a ) { eval ( h.hReq.responseText ); }, url, true, null );
}

