function CreateXMLHttp()
{
	if (typeof XMLHttpRequest != "undefined") {
		return new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		// "MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
		var aVersions = ["MSXML2.XMLHttp","MSXML.XMLHttp"];
		for (var i = 0; i < aVersions.length; i++)
		try {
			var oXmlHttp = new ActiveXObject(aVersions[i]);
			return oXmlHttp;
		} catch (oError) {
			//sss
		}
	}
	throw new Error("Не установлена библиотека MSXML.");
}

function EvalAJAXScripts(obj)
{
   scripts_arr = obj.getElementsByTagName("script");
   for(i in scripts_arr) if (scripts_arr[i].text !== "" && scripts_arr[i].text !== null) eval(scripts_arr[i].text);
}

function send_data(url_link,response_function)
{
	var state_div = document.getElementById('status-panel-center');
	if (state_div != null && state_div != "undefined") state_div.innerHTML = 'Состояние: посылка запроса.';
	
	var oXmlHttp = CreateXMLHttp();
	oXmlHttp.open("get",url_link,true);
	oXmlHttp.setRequestHeader("Content-Type", "text/xml; charset=windows-1251");
	oXmlHttp.onreadystatechange = function ()
	{
		var state_div = document.getElementById('status-panel-center');
		
		if (oXmlHttp.readyState == 4){
			if (oXmlHttp.status == 200)
			{
				if (state_div != null && state_div != "undefined") state_div.innerHTML = 'Состояние: готово.';
				
				if (response_function!="")
				{
					if (document.all[response_function]!=null&&document.all[response_function]!="undefined")
					{
						document.all[response_function].innerHTML = oXmlHttp.responseText;
						EvalAJAXScripts(document.all[response_function]);
					} else {
						response_function(oXmlHttp.responseText);
					}
				}
			} else {
				if (state_div != null && state_div != "undefined") state_div.innerHTML = 'Состояние: ошибка.';
				alert('Error');
			}
		}
	}
	oXmlHttp.send(null);
	if (state_div != null && state_div != "undefined") state_div.innerHTML = 'Состояние: ожидание ответа.';
}

function send_post_data(url_link,form,response_function)
{
	var oForm = document.all[form];
	var sBody = getRequestBodyURI(form);
	var oXmlHttp = CreateXMLHttp();
	oXmlHttp.open("post",url_link,true);

	oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oXmlHttp.onreadystatechange = function ()
	{
		if (oXmlHttp.readyState == 4){
			if (oXmlHttp.status == 200)
			{
				if (response_function!="")
				{
					if (document.all[response_function]!=null&&document.all[response_function]!="undefined")
					{
						document.all[response_function].innerHTML = oXmlHttp.responseText;
						EvalAJAXScripts(document.all[response_function]);
					} else {
						response_function(oXmlHttp.responseText);
					}
				}
			} else {
				alert('Error');
			}
		}
	}
	//alert(sBody)
	oXmlHttp.send(sBody);
}

function resp(data)
{
	alert(data);
}
