var ajax = function() {
	this.onDataReady = null;
	this.onXmlDataReady = null;
	this.onDataReadyParams = null;
	this.onXmlDataReadyParams = null;
	this.method = "POST";
	this.url = null;
	this.async = true;
	this.username = null;
	this.password = null;
	this.params = null;
	
	this.getXMLHTTP = function() {
		var xmlHttp = null;

		try {
			xmlHttp = new XMLHttpRequest();
		}
		catch (e) {
			var progIds = ['MSXML2.XMLHTTP', 'Microsoft.XMLHTTP', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0'];
			var success = false;
			for( var iterator = 0; (iterator < progIds.length) && (!success); iterator++ ) {
				try {
					xmlHttp = new ActiveXObject( progIds[iterator] );
					success = true;
				}
				catch (e) {}
			}
			if ( !success ) {
				return null;
			}
		}
		return xmlHttp;
	};
	
	this.setXmlDataReadyParams = function() {
		this.onXmlDataReadyParams = this.setXmlDataReadyParams.arguments;
	}
	
	this.setDataReadyParams = function() {
		this.onDataReadyParams = this.setDataReadyParams.arguments;
	}
	
	this.exec = function() {
		var ajaxObject = this.getXMLHTTP();
		thisClass = this;
		
		if( this.async ) {
			ajaxObject.onreadystatechange = function() {
				if( ajaxObject.readyState == 4 ) {
					if( ajaxObject.status == 200 ) {
						if( thisClass.onDataReady && ( typeof( thisClass.onDataReady ) == 'function' ) ) {
							if( thisClass.onDataReadyParams ) thisClass.onDataReady( ajaxObject.responseText, thisClass.onDataReadyParams );
							else thisClass.onDataReady( ajaxObject.responseText );
						}
						if( thisClass.onXmlDataReady && ( typeof( thisClass.onXmlDataReady ) == 'function' ) ) {
							if( thisClass.onXmlDataReadyParams ) thisClass.onXmlDataReady( ajaxObject.responseXML, thisClass.onXmlDataReadyParams );
							else thisClass.onXmlDataReady( ajaxObject.responseXML );
						}
					}
				}
			}
		}
		
		ajaxObject.open( this.method, this.url, this.async, this.username, this.password );
		if( this.method.toLowerCase() == "post" ) {
			ajaxObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		}
		ajaxObject.send( this.params );

		if( !this.async ) {
			if( this.onDataReady && ( typeof( this.onDataReady ) == 'function' ) ) {
				this.onDataReady( ajaxObject.responseText );
			}
			if( this.onXmlDataReady && ( typeof( this.onXmlDataReady ) == 'function' ) ) {
				this.onXmlDataReady( ajaxObject.responseXML );
			}
		}
	}
};

