function DisableScreenOld(str)
{
	var div = document.getElementById("LockScreenDiv");
	if (div == null)
	{
		div = document.createElement('div');
		div.id = 'LockScreenDiv';
		//div.onclick=EnableScreen;
		document.body.appendChild(div);
	}
	div.className = "DisabledScreen";
	if (str !== undefined) //if (typeof(str) != 'undefined')
		div.innerHTML = str;//div.innerHTML + str;
}

function EnableScreenOld(str)
{
	var div = document.getElementById("LockScreenDiv");
	div.className = "EnabledScreen";
}

// Код вызова
var call_code;
// Объект класса XMLHttpRequest
var xmlHttp;

function GetPostVars(vars)
{
	var res = '';
	for (var key in vars)
	{
		if (res != '') res += '&';
		res += encodeURIComponent(key) + '=' + encodeURIComponent(vars[key])
	}
	return res;
}

function CallAjax(url, callback_function, post_vars)
{
	if (post_vars == undefined) post = false; else post = true;
	if (xmlHttp == undefined)
	{
		// Если имеем дело не с InternetExplorer
		if (window.XMLHttpRequest)
			xmlHttp = new XMLHttpRequest();
		else if (window.ActiveXObject)
			// Если имеем дело с InternetExplorer(он объект XMLHttpRequest имеет
			// в виде active-X компонента XMLHTTP)
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	// Установить функцию для сервера, которая выполнится после его ответа
	xmlHttp.onreadystatechange = callback_function;//updatePage;

	// Открыть соединение с сервером
	if (post)
		xmlHttp.open("POST", url, true);
	else
		xmlHttp.open("GET", url, true);
	// Передать запрос
	if (post)
	{
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		var params = GetPostVars(post_vars);//'name=' + encodeURIComponent(name) + '&surname=' + encodeURIComponent(surname);
		xmlHttp.send(params);
	}
	else
		xmlHttp.send(null);

	// Включить индикатор загрузки
	//DisableScreen('Loading...');
}

// Функция, выполняемая после ответа
/*function updatePage() {
  if (xmlHttp.readyState == 4) {

        if (xmlHttp.status == 200) {
            // Если код ошибки - 200 подгружем ответ сервера в элемент HTML с
            // ID=call_code
            document.getElementById(call_code).innerHTML = xmlHttp.responseText;
			EnableScreen();
        } else {
            alert("Не удалось получить данные:\n" + xmlHttp.statusText);
        }

  }
}*/





function Ajax()
{
	this.requestObj = null;
	var obj = this;
	
	if (window.XMLHttpRequest)
	{
		this.requestObj = new XMLHttpRequest;
	}
	else if (window.ActiveXObject)
	{
		this.requestObj = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else return null;
	
	this.stateChange      = new Object;
	this.stateChange.obj  = this;
	////  ////  ////  ////  ////  ////  ////  ////  ////  ////
	
	this.stateChange = function ()
	{
		this.htmlCode = null;
		 
		   // alert(obj.parameters);
		if (obj.requestObj.readyState == 4)
		{
			if(obj.reqFunc){
				obj.reqFunc(obj.requestObj.responseText);
				return true; 
			}
		}
	}
	
	////  ////  ////  ////  ////  ////  ////  ////  ////  ////
	this.addHTML = function (id, code)
	{
		document.getElementById(id).innerHTML = code;
	}
	
	////  ////  ////  ////  ////  ////  ////  ////  ////  ////
	this.getState = function(){
		return obj.requestObj.readyState;
	}
	
	////  ////  ////  ////  ////  ////  ////  ////  ////  ////
	this.setParams = function(s_url, s_method, s_parameters, func){
		obj.url        = s_url;
		obj.method     = s_method;
		obj.parameters = s_parameters;
		obj.reqFunc    = func;
		   
		if (
			obj.method != "POST" && 
			obj.method != "GET" && 
			obj.method != 'post' && 
			obj.method != 'get'
			) obj.method = "POST";
	   
	}
	
	////  ////  ////  ////  ////  ////  ////  ////  ////  ////
	this.sendRequestOld = function ()
	{ 
		obj.requestObj.onreadystatechange = obj.stateChange;
		obj.requestObj.open(obj.method, obj.url, true);
		obj.requestObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		obj.requestObj.send(obj.parameters);
	}
	
	this.GetPostVars = function(vars, sub) {
		var res = '';
		for (var key in vars)
		{
			if (res != '') res += '&';
			if (typeof(vars[key]) == 'object')
			{
				if (sub == undefined)
					res += this.GetPostVars(vars[key], encodeURIComponent(key));
				else
					res += this.GetPostVars(vars[key], sub+'['+encodeURIComponent(key)+']');
			}
			else
			{
				if (sub == undefined)
					res += encodeURIComponent(key) + '=' + encodeURIComponent(vars[key])
				else
					res += sub+'['+encodeURIComponent(key)+']' + '=' + encodeURIComponent(vars[key])
			}
		}
		return res;
	}
	
	this.sendRequest = function (url, params, method, func)
	{
		if (!method) method = "POST";
		
		if (params != undefined)
			params = this.GetPostVars(params);
		
		obj.reqFunc = func;
		this.requestObj.onreadystatechange = this.stateChange;
		this.requestObj.open(method,url,true);
		this.requestObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		this.requestObj.send(params);
		return this.requestObj;
	}
}
