var req = null;

var READY_STATE_UNINITIALIZED = 0;
var READY_STATE_LOADING = 1;
var READY_STATE_LOADED = 2;
var READY_STATE_COMPLETE = 4;



function loadXMLDoc(url,post)
{
	if (window.XMLHttpRequest) // branch for native XMLHttpRequest object
		req = new XMLHttpRequest();
	else if (window.ActiveXObject) // branch for IE/Windows ActiveX version
		req = new ActiveXObject("Microsoft.XMLHTTP");

	document.body.style.cursor = 'wait';

	if (req)
	{
		//req.overrideMimeType('text/xml');
		req.onreadystatechange = processReqChange;
		if ( post )
		{
			req.open("POST", url, true);
			req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			//req.setRequestHeader('Accept-Charset', 'windows-1251,utf-8;q=0.7,*;q=0.7');
			req.send(post);
		}
		else
		{
			req.open("GET", url, true);
			req.send(null);
		}
	}
	else
		alert("There was a problem communicating with XMLHttpRequest object in your browser!");
}



function processReqChange()
{
	try
	{
		if (req.readyState == READY_STATE_COMPLETE) // only if req shows "complete"
		{
			if (req.status == 200) // only if "OK"
			{
				document.body.style.cursor = 'auto';
				// ...processing statements go here...
				response = req.responseXML.documentElement;
				method = response.getElementsByTagName('method')[0].firstChild.data;
				result = response.getElementsByTagName('result')[0].firstChild.data;
				eval(method+'(result)');
			}
			else
			{
				document.body.style.cursor = 'auto';
				alert("There was a problem retrieving the XML data:\n" + req.statusText);
			}
		}
	}
	catch( e )
	{
		document.body.style.cursor = 'auto';
		alert('Критическая ошибка: ' + e.description);
	}
}




var ajax_Form;
var ajax_InProgress;
var ajax_Complete;
var ajax_Error;


function ajax_Init(dlg_name)
{
	ajax_Form = document.getElementById('ajax_Form_'+dlg_name).style;
	ajax_InProgress = document.getElementById('ajax_InProgress_'+dlg_name).style;
	ajax_Complete = document.getElementById('ajax_Complete_'+dlg_name).style;
	ajax_Error = document.getElementById('ajax_Error_'+dlg_name).style;
}


function ajaxTaskForm()
{
	ajax_Form.display = 'block';
	ajax_InProgress.display = 'none';
	ajax_Complete.display = 'none';
	ajax_Error.display = 'none';
}

function ajaxTaskInProgress()
{
	ajax_Form.display = 'none';
	ajax_Error.display = 'none';
	ajax_Complete.display = 'none';
	ajax_InProgress.display = 'block';
}

function ajaxTaskComplete()
{
	ajax_Form.display = 'none';
	ajax_InProgress.display = 'none';
	ajax_Error.display = 'none';
	ajax_Complete.display = 'block';
}

function ajaxTaskError()
{
	ajax_Form.display = 'none';
	ajax_InProgress.display = 'none';
	ajax_Complete.display = 'none';
	ajax_Error.display = 'block';
}

