var XMLHTTP_IDS = new Array(
	'MSXML2.XMLHTTP.5.0',
	'MSXML2.XMLHTTP.4.0',
	'MSXML2.XMLHTTP.3.0',
	'MSXML2.XMLHTTP',
	'Microsoft.XMLHTTP'
);

function MyHttp(){
	this.success = false;
	this.xmlHttp=0;
	//this.createRequest();
}

MyHttp.prototype.createRequest = function(){
	
	this.success=false;
	this.xmlHttp=0;
	
	if (this.xmlHttp)
		delete this.xmlHttp;

	try {
		// Mozilla / Safari
		this.xmlHttp = new XMLHttpRequest();
		this.success = true;
	} catch (e) {
		// IE
		
		for (var i=0;i < XMLHTTP_IDS.length && !this.success; i++) {
			try {
				this.xmlHttp = new ActiveXObject(XMLHTTP_IDS[i]);
				this.success = true;
			} catch (e) {}
		}
	}

	this.success=false;

	if (!this.success) {
	//	alert('Cant create XMLHttpRequest!');
		return;
	}
}

MyHttp.prototype._callback = function(){
	if (!this.callback)
		return;

	var e;
	
	if (this.xmlHttp.readyState == 4){// Download complete
		if (this.xmlHttp.status == 200){
			var now = new Date();
			this.endTime = now.getTime();
			this.callback(this.xmlHttp.responseText, this.endTime-this.startTime);
		}else{
			
			this.callback("Ошибка " + this.xmlHttp.status + " " + this.xmlHttp.statusText);
		}
	}
}

MyHttp.prototype.get = function(_url){
	this.createRequest();
	
	if (!this.success || !this.xmlHttp)	
		return false;

	var now = new Date();
	this.startTime = now.getTime();
	
	// Guaranteed reloading of the page
	if (_url.indexOf("?") == -1)
		this.url = _url+"?rnd="+Math.random();
	else
		this.url = _url+"&rnd="+Math.random();
		
	this.xmlHttp.open("GET",this.url,true);

	var obj = this;
	this.xmlHttp.onreadystatechange = function(){ obj._callback(this);};
	this.xmlHttp.send("");
	
	return true;
};

MyHttp.prototype.cancel = function(){
	this.xmlHttp.abort();
}



