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)
{

//alert("2");

	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';
	
	//myalert( "req", req );

	var path = url;
	if( post != "" ) path = path + "?" + post;
	
	if (req)
	{
		//req.overrideMimeType('text/xml');
		req.onreadystatechange = processReqChange;
		if ( path != "" )
		{
			req.open("GET", path, true);
			//myalert( "open", 1 );
			//req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			//req.setRequestHeader('Accept-Charset', 'windows-1251,utf-8;q=0.7,*;q=0.7');
			//myalert( "Header", 1 );
			//req.send(post);
			req.send(null);
			//myalert( "send", 1 );
		}
		//else
		//{
			//req.open("GET", url, true);
			//req.send(null);
		//}
	}
	else
		alert("There was a problem communicating with XMLHttpRequest object in your browser!");
}

function loadXMLDoc2(url, post)
{

//alert("2");

	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;
				cart_price = response.getElementsByTagName('cart_price')[0].firstChild.data;
				cart_count = response.getElementsByTagName('cart_count')[0].firstChild.data;
				eval(method+'(result,cart_price,cart_count)');
			}
			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);
	}
}


