/**
 *
 * VisualHotels HttpRequest
 *
 */
function VH_HttpRequest(url, returntype, method, vars)
{
	// query params
	this._returnType = returntype;
	this._url = url;
	//document.writeln(this._url);
	this._method = method;
	this._vars = vars;
	
	// return value
	this._returnValue = null;
	
	// req
	this._req = false;
	
	
	// flag
	this._flag = false;
	
	
	this.getResult = function()
	{
		if ( !this._flag )
		{
			this._flag=true;
			this._createRequest();
			this._initProgress();
		}
		
		return this._returnValue;
	};
	
	
	// create request
	this._createRequest = function()
	{
		if (window.XMLHttpRequest)
		{
			this._req = new XMLHttpRequest();
			
			if (this._req.overrideMimeType)
			{
				this._req.overrideMimeType('text/xml');
			}
		}
		else if (window.ActiveXObject)
		{
			try
			{
				this._req = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e)
			{
				try
				{
					this._req = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e)
				{
					;
				}
			}
		}
	};
	
	
	// init progress
	this._initProgress = function()
	{
		if ( !this._req )
		{
			this._createRequest();
		}
		
		if (this._req)
		{
			this._req.open(this._method, this._url, true);
			this._req.onreadystatechange = function(object)
										{
											return function()
											{
												object._initProgressResponse(object._req);
											}
										} (this);
			
			this._req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset-Windows-1251");
			this._req.send(this._vars);
		}
	};
	
	
	// init progress response
	this._initProgressResponse = function(req)
	{
		if ( req.readyState == 4 )
		{
			if (req.status == 200)
			{
				switch ( this._returnType )
				{
					case 'json':
						try
						{
							eval('var __VH_JSON__ = ' + req.responseText);
							this._returnValue = __VH_JSON__;
						}
						catch(e)
						{
							//alert('ÎØÈÁÊÀ: '+e.message);
						}
						
						break;
					
					case 'xml':
						//this._returnValue = __VH_JSON__;
						//this.xml = OpenXML.load_xml(req.responseText);
						break;
				}
			}
			else
			{
				// error
			}
		}
	};
};