//It is functions for sending AJAX requests to server-----------------------------

var xmlHttp;
function createXMLHttpRequest() 
{
	if (window.XMLHttpRequest) 
	{
		xmlHttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
}


 function AddToBasket(good_id)
 {
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = GetItemForBasket;
	xmlHttp.open("POST", "/ajax_func.php", true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send("ajaxmetod=addtobasket&good_id="+good_id);
 } 
 
function GetItemForBasket(good_id) 
{
	if(xmlHttp.readyState == 4) 
	{
		if(xmlHttp.status == 200) 
		{
			var BasketItems = xmlHttp.responseText.split("^");
			try
			{
				document.getElementById("TBasket").innerHTML = BasketItems[1];
			}
			catch(e){}
			alert(BasketItems[0]);
			
		}
		else
		{
			alert(xmlHttp.statusText);
		}
	}
}






function Autent(login, pass)
{
		createXMLHttpRequest();
		xmlHttp.onreadystatechange = GetResultError;
		xmlHttp.open("POST", "/ajax_func.php", true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.send("ajaxmetod=autentification&login="+login.value+"&pass="+pass.value);
}

function GetResultError() 
{
	if(xmlHttp.readyState == 4) 
	{
		if(xmlHttp.status == 200) 
		{
				var TextResult = xmlHttp.responseText;
				if (TextResult.substring(0,3) != '1--')
				{
					alert(TextResult);
				}
				else
				{
					//alert(TextResult.substring(3));
					location.href = TextResult.substring(3);
			    }
		}
		else
		{
			alert(xmlHttp.statusText);
		}
	}
}

function Reg() 
{
	location.href("/registration.php");
}

 function addsrv()
 {
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = Getsrv;
	xmlHttp.open("POST", "/ajax_func.php", true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send("ajaxmetod=addsrv");
	
 } 
 
function Getsrv() 
{
	if(xmlHttp.readyState == 4) 
	{
		if(xmlHttp.status == 200) 
		{
			var srvItems = xmlHttp.responseText;
			try
			{
				location.href = "/index.php";
			}
			catch(e){}
		}
		else
		{
			alert(xmlHttp.statusText);
		}
	}
}

 

