/**
* 	@package XMLHTTPRequest Stub
*   @author Kalapuc Roman (kalapuc@finport.net)
*/

function XMLHTTPStub(_sURL)
{		
	this.sURL = _sURL;
}

XMLHTTPStub.prototype._request = undefined;

XMLHTTPStub.prototype.get = function()
{
	this._request = this._getXMLHTTPRequest();		
	var _this = this;
	
	this._request.onreadystatechange = function(){_this._process()};
	this._request.open("GET",this._getURL(), true);
	this._request.send(null);
}


XMLHTTPStub.prototype._getURL = function()
{	
	return this.sURL;
}

XMLHTTPStub.prototype._process = function()
{
	
	if(this._request.readyState == 4)
	{
		
		if(this._request.status == "200")
		{			
			if(this.onLoad != undefined)
			{				
				this.onLoad(this._request.responseText);
			}
		}
		else
		{	
			if(this.onError != undefined)
			{
				this.onError({status:this_request.status,statusText:this._request.statusText});
			}
		}
		
		delete this._request;
	}
}

XMLHTTPStub.prototype._getXMLHTTPRequest = function()
{
	var xmlHttp;
	try
	{
		xmlHttp = new ActiveXObject("Msxml2.XMLHttp");
	}
	catch(e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
		}
		catch(e2)
		{
		}
	}
	
	if(xmlHttp == undefined && (typeof XMLHttpRequest != 'undefined'))
	{
		xmlHttp = new XMLHttpRequest();
	}
	
	return xmlHttp;
}

function getRandomString(len){
	var resStr='';
	var alphabet ='aAbBcCdDeEfFgGhHhjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789';
	for (i=0;i<len;i++){
		j = Math.floor(Math.random()*66);
		resStr+=alphabet.substr(j,1);
	}
	return resStr;
} 