Function.prototype.override = function (source) {
	if (!source)
		return;
	for (var property in source)
		this.prototype[property] = source[property];
	return this;
};

Function.create = function (source) {
	var instance;
	if (source.hasOwnProperty("constructor"))
		instance = source.constructor;
	else
		instance = function (){};
	instance.override(source);
	return instance;
};

Function.override({
	extend: function (source) {
		var instance = Function.create();
		instance.prototype = new this();
		instance.prototype.constructor = instance;
		instance.prototype.parent = this.prototype;
		instance.override(source);
		return instance;
	},
	bind: function (scope) {
		var callBack = this;
		return function () {
			return callBack.apply(scope, arguments);
		};
	}
});

Http = {};
Http.RequestFactory = Function.create({
	newInstance: function () {
		var request;
		if (window.XMLHttpRequest)
			request = new XMLHttpRequest();
		else
			request = new ActiveXObject("Microsoft.XMLHTTP");
		return request;
	}
});
Http.Connection = Function.create({
	requestFactory: new Http.RequestFactory(),
	method: "POST",
	sync: false,
	head: null,
	body: null,
	constructor: function () {
		this.request = this.requestFactory.newInstance();
	},
	setUrl: function (url) {
		this.url = url;
	},
	setHead: function (head) {
		this.head = head;
	},
	setBody: function (body) {
		this.body = body;
	},
	setCallBack: function (callBack) {
		this.callBack = callBack;
	},
	query: function () {
		this.request.open(this.method, this.url, !this.sync);
		this.request.onreadystatechange = this.responseObserver.bind(this);
		if (this.head)
			for (header in this.head)
				if (this.head.hasOwnProperty(header))
					this.request.setRequestHeader(header, this.head[header]);
		this.request.send(this.body);
	},
	responseObserver: function () {
		if (this.request.readyState != 4)
			return;
		var response = null;
		if(this.request.status == 200)
			response = this.request.responseText;
		this.callBack.call(this, response);
	}
});
