var net = new Object();
net.READY_STATE_UNINITIALIZED = 0;
net.READY_STATE_LOADING       = 1;
net.READY_STATE_LOADED        = 2;
net.READY_STATE_INTERACTIVE   = 3;
net.READY_STATE_COMPLETE      = 4;
/*******************************************************/
net.ContentLoader = function(url, onLoad, onError, method, params, contentType)
{
	this.req     = null;
	this.url     = url;
	this.onload  = onLoad;//функция обработки XML данных
	this.onerror = (onError) ? onError : this.defaultError;//функция обработки ошибки при выдачи битых данных с сервера
	this.method  = (method) ? method : 'GET';
	this.params  = (params) ? params : null;
	this.contentType = (!contentType && this.method == 'POST') ? 'application/x-www-form-urlencoded; charset=koi8-u' : contentType;
	
	//this.contentType = (!contentType && this.method == 'POST') ? 'application/x-www-form-urlencoded; ' : contentType;
	this.contentType = 'application/x-www-form-urlencoded; charset=koi8-u'; 
	this.loadXMLDoc(url);
}
/*******************************************************/
net.ContentLoader.prototype.initXMLHTTPRequest = function()
{
	this.req = null;
	if (window.XMLHttpRequest)
	{//проверка на встроеный объект XML в сам браузер (Mozilla/Safari)
		this.req = new XMLHttpRequest();
	}
	else
	{
		if (typeof ActiveXObject != 'undefined')
		{//проверка на поддержку браузера ActiveX
			this.req = new ActiveXObject('Microsoft.XMLHTTP');//IExplorer
		}
		else
			alert("Не возможно инициализировать \"XMLHttpRequest\"" + 
						"\nустановите себе Mozilku");
	}
}
/*******************************************************/
net.ContentLoader.prototype.loadXMLDoc = function(url)
{
	this.initXMLHTTPRequest();//здесь нужно инициализировать его по любому ВСЕГДА (патаму ша ActiveX-бля)
	if (this.req)
	{
		try
		{
			var loader = this;
			this.req.onreadystatechange = function()
			{
				loader.onReadyState.call(loader);
			}

			this.req.open(this.method, url, true);

			if (this.contentType)
				this.req.setRequestHeader('Content-Type', this.contentType);
				
			this.req.send(this.params);
		}
		catch (err)
		{
			this.onerror.call(this);
		}
	}
}
/*******************************************************/
net.ContentLoader.prototype.onReadyState = function()
{//метод контроля получения запроса от сервера
	var ready = this.req.readyState;
	if (ready == net.READY_STATE_COMPLETE)
	{//сервер выдал полностью ответ
		var httpStatus = this.req.status;
		if (httpStatus==200 || httpStatus==0)
		{//код 200 - http запрос выполнен успешно
			//var xmlDoc = this.req.responseXML.documentElement; 
			//var htmlText = this.req.responseText;
			//alert(htmlText);
			//this.onload(htmlText);
			this.onload();
		}
		else
			this.onerror.call(this);
	}
}
/*******************************************************/
net.ContentLoader.prototype.defaultError = function()
{
	document.body.style.cursor = 'default';
	if(elid) {
		elid.style.display = 'none';
	}
	alert("сервер выдал битые данные!" +
				"\n\nreadyState: " + this.req.readyState +
				"\nhttpStatus: " + this.req.status + 
				"\nheaders: " + this.req.getAllResponseHeaders());
}
/*******************************************************/
