function HttpClient() { }
HttpClient.prototype = {
	// type GET,POST passed to open
	requestType:'POST',
	// when set to true async calls are made
	isAsync:false,

	// where an XMLHttpRequest instance is stored
	xmlhttp:false,

	// what is called when a successful async call is made
	callback:function(responseText) {
		document.getElementById('HttpClientStatus').innerHTML = responseText;	
	},

	// what is called when send is called on XMLHttpRequest
	// set your own function to onSend to have a custom loading effect
	onSend:function() {
		document.getElementById('HttpClientStatus').innerHTML = '<img src="images/loader.gif" alt="Processing" width="16" height="16" />&nbsp; Processing';
	},

	// what is called when when readyState 4 is reached, this is called before your callback
	onLoad:function() {
		document.getElementById('HttpClientStatus').innerHTML = '';
	},

	// what is called when an http error happens
	onError:function(error) {
		alert(error.message);
	},
	
	// method to initialize an xmlhttpclient
	init:function() {
		try {
		    // Mozilla / Safari
		    this.xmlhttp = new XMLHttpRequest();
		} catch (e) {
			// IE
			var XMLHTTP_IDS = new Array(
			'MSXML2.XMLHTTP.5.0',
			'MSXML2.XMLHTTP.4.0',
			'MSXML2.XMLHTTP.3.0',
			'MSXML2.XMLHTTP',
			'Microsoft.XMLHTTP' );
			var success = false;
			for (var i=0;i < XMLHTTP_IDS.length && !success; i++) {
				try {
					this.xmlhttp = new ActiveXObject(XMLHTTP_IDS[i]);
					success = true;
				} catch (e) {}
			}
			if (!success) {
				throw new Error('Unable to create XMLHttpRequest.');
			}
		}
	},

	// method to make a page request
	// @param string url  The page to make the request too
	// @param string payload  What your sending if this is a POST request
	// @param string contentType  contentType to set, optional
	makeRequest: function(url,payload,contentType) {
		if (!this.xmlhttp) {
			this.init();
		}
		this.xmlhttp.open(this.requestType,url,this.isAsync);
		if (contentType) {
			this.xmlhttp.setRequestHeader('Content-Type',contentType);
		}

		// set onreadystatechange here since it will be reset after a completed call in Mozilla
		var self = this;
		this.xmlhttp.onreadystatechange = function() { self._readyStateChangeCallback(); }

		this.xmlhttp.send(payload);

		if (!this.isAsync) {
			return this.xmlhttp.responseText;
		}
	},
	

	// internal method used to handle ready state changes
	_readyStateChangeCallback:function() {
		//4 = completed
		if (this.xmlhttp.readyState == 4) {
			//Clear pre-loader icon
			this.onLoad();
			//Make sure server status is "OK"
			if (this.xmlhttp.status == 200) {
				this.callback(this.xmlhttp.responseText);
			} else {
				//An error occurred
				this.onError(new Error('HTTP Error Making Request: ['+this.xmlhttp.status+'] '+this.xmlhttp.statusText));
			}
		} else {
			//Show pre-loader
			this.onSend();
		}
	}
}