var WebKit = {
	version: "1.0",
	options: "",
	url: "",
	notify: function (msg) {
		alert(msg);
	},
	xhrRequest: function (url, options) {
		this.url = (typeof (url) == 'undefined') ? '' : url;
		this.options = (typeof (options) == 'undefined') ? '' : options;
		this.makeRequest();
	},
	makeRequest: function () {
		this.xhrInstance = this.getXMLHttpRequest(); 
		if (this.xhrInstance != null && this.url != '') {
			var post_data = null;
			if (typeof (this.options.params) != 'undefined') {
				this.url = this.url + '?' + this.options.params;
			}
			this.options.method = (typeof (this.options.method) == 'undefined') ? "POST" : this.options.method;
//			alert("URL = " + this.url);
			this.xhrInstance.open(this.options.method, this.url, true);
			if (this.options.method == "POST") {
				this.xhrInstance.setRequestHeader("Content-type","application/x-www-form-urlencoded");
				post_data = (typeof (this.options.post_data) == 'undefined') ? null : this.options.post_data;
			}
			var oInst = this;
			this.xhrInstance.onreadystatechange = function () {oInst.handleResponse(oInst)};
			this.xhrInstance.send(post_data);
		}
	},
	getXMLHttpRequest: function (originalInstance) {
		var activeXVersions = ["Msxml2.DOMDocument.6.0","Msxml2.DOMDocument.3.0","Msxml2.XMLHTTP","Microsoft.XMLHTTP"];
		try {
			return new XMLHttpRequest;
		} catch (e) {
			for (var i=0; i < activeXVersions.length; i++) {
				try {
					return new ActiveXObject(activeXVersions[i]);
				} catch (e) {}
			}
		}
		return null;
	},
	handleResponse: function (originalInstance) {
		if (originalInstance.xhrInstance.readyState == 4) {
			if (originalInstance.xhrInstance.status == 200) {
				if (typeof (originalInstance.options.onSuccess) != 'undefined') {
					originalInstance.options.onSuccess(originalInstance.xhrInstance);
				}
			} else {
				if (typeof (originalInstance.options.onFailure) != 'undefined') {
					originalInstance.options.onFailure(originalInstance.xhrInstance);
				}				
			}
			if (typeof (originalInstance.options.onComplete) != 'undefined') {
				originalInstance.options.onComplete(originalInstance.xhrInstance);
			}
			originalInstance.cleanUp(originalInstance);
		}
	},
	cleanUp: function (originalInstance) {
		originalInstance.options.onSuccess = null;
		originalInstance.options.onFailure = null;
		originalInstance.options.onComplete = null;
		originalInstance.xhrInstance.onreadystatechange = null;
		originalInstance.xhrInstance = null;
		originalInstance = null;
	},
	abort: function () {
		if (this.xhrInstance) {
			this.xhrInstance.abort();
			this.cleanUp(this.xhrInstance);
		}
	}
}
