document.charset="windows-1251";
// =======================================
	var xmlHttp1;
	var xmlHttp2;
	var xmlHttp3;
	var xmlHttp4;
	var xmlHttp5;
	var xmlHttp6;
	if (window.XMLHttpRequest) {
		try {
			xmlHttp1 = new XMLHttpRequest();
			xmlHttp2 = new XMLHttpRequest();
			xmlHttp3 = new XMLHttpRequest();
			xmlHttp4 = new XMLHttpRequest();
			xmlHttp5 = new XMLHttpRequest();
			xmlHttp6 = new XMLHttpRequest();
		} catch (e){}
	} else if (window.ActiveXObject) {
		try {
			xmlHttp1 = new ActiveXObject('Msxml2.XMLHTTP');
			xmlHttp2 = new ActiveXObject('Msxml2.XMLHTTP');
			xmlHttp3 = new ActiveXObject('Msxml2.XMLHTTP');
			xmlHttp4 = new ActiveXObject('Msxml2.XMLHTTP');
			xmlHttp5 = new ActiveXObject('Msxml2.XMLHTTP');
			xmlHttp6 = new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e){
			try {
				xmlHttp1 = new ActiveXObject('Microsoft.XMLHTTP');
				xmlHttp2 = new ActiveXObject('Microsoft.XMLHTTP');
				xmlHttp3 = new ActiveXObject('Microsoft.XMLHTTP');
				xmlHttp4 = new ActiveXObject('Microsoft.XMLHTTP');
				xmlHttp5 = new ActiveXObject('Microsoft.XMLHTTP');
				xmlHttp6 = new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e){}
		}
	}


		function loadQuote(id)
	{
		if (xmlHttp1)
		{    
			try
			{	
				var game = "site=1&itemID=" + id;
				xmlHttp1.open("POST", "imageQuote.php", true); 
				xmlHttp1.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				xmlHttp1.onreadystatechange = requestProc1; 
				xmlHttp1.send(game); 
	 
			}
			catch (e)
			{ 
				// alert("Не удалось соединиться с сервером [1]:\n" + e.toString());     
			}   
		}
	}

	function requestProc1()
	{
		if (xmlHttp1)
		{
			if(xmlHttp1.readyState == 4)
			{
				if(xmlHttp1.status==200) 
				{
					document.getElementById("imgQuote").innerHTML = xmlHttp1.responseText;
				}
			}
		}
	}

	function search()
	{
		document.getElementById("text").innerHTML = "<center>Поиск<br><br><img src=\"images/progbar.gif\" title=\"\"  border=\"0\"></center>";
		var str = document.getElementById('name1').value;
		// alert(str);
		if (xmlHttp2)
		{    
			try
			{	
				var game = "site=1&str=" + str;
				xmlHttp2.open("POST", "search.php", true); 
				xmlHttp2.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				xmlHttp2.onreadystatechange = requestProc2; 
				xmlHttp2.send(game); 
	 
			}
			catch (e)
			{ 
				alert("Не удалось соединиться с сервером [2]:\n" + e.toString());     
			}   
		}
	}

	function requestProc2()
	{
		if (xmlHttp2)
		{
			if(xmlHttp2.readyState == 4)
			{
				if(xmlHttp2.status==200) 
				{
					document.getElementById("text").innerHTML = xmlHttp2.responseText;
				}
			}
		}
	}
	// ========================================
	
	// Прокрутка от top
	function getBodyScrollTop()
	{
		return self.pageYOffset || 
			(document.documentElement && document.documentElement.scrollTop) || 
			(document.body && document.body.scrollTop);
	}
	function closeQuote(){
		document.getElementById("quote").style.visibility = "hidden";
	}
	function openCart(){
		getItemsCart('1');
		var divTop = 350 + getBodyScrollTop();
		document.getElementById("cart_div").style.height = document.body.scrollHeight + "px";
		document.getElementById("cart_div2").style.top = divTop + "px";
		document.getElementById("cart_div").style.visibility = "visible";
	}
	function closeCart(){
		document.getElementById("cart_div").style.visibility = "hidden";
	}

	function openMenu(i){
		document.getElementById("menu"+i).style.visibility = "visible";
	} 
	function closeMenu(i){

	}
	
	function addToCart(id)
	{
		if (xmlHttp3)
		{    
			try
			{	
				var game = "site=1&itemID=" + id;
				xmlHttp3.open("POST", "addToCart.php", true); 
				xmlHttp3.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				xmlHttp3.onreadystatechange = requestProc3; 
				xmlHttp3.send(game); 
	 
			}
			catch (e)
			{ 
				alert("Не удалось соединиться с сервером [3]:\n" + e.toString());     
			}   
		}
	}

	function requestProc3()
	{
		if (xmlHttp3)
		{
			if(xmlHttp3.readyState == 4)
			{
				if(xmlHttp3.status==200) 
				{
					var response = xmlHttp3.responseText;
					var text = response.split('[split]');
					document.getElementById("items").innerHTML = text[0];
					document.getElementById("count").innerHTML = text[1];
					alert("Товар успешно добавлен в корзину.");
				}
			}
		}
	}

	function getItemsCart(step)
	{
		if (xmlHttp4)
		{    
			try
			{	
				var game = "site=1&step=" + step;
				xmlHttp4.open("POST", "getItemsCart.php", true); 
				xmlHttp4.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				xmlHttp4.onreadystatechange = requestProc4; 
				xmlHttp4.send(game); 
	 
			}
			catch (e)
			{ 
				alert("Не удалось соединиться с сервером [4]:\n" + e.toString());     
			}   
		}
	}

	function requestProc4()
	{
		if (xmlHttp4)
		{
			if(xmlHttp4.readyState == 4)
			{
				if(xmlHttp4.status==200) 
				{
					document.getElementById("itemsCart").innerHTML = xmlHttp4.responseText;
				}
			}
		}
	}

	function goOrder()
	{
		if (xmlHttp5)
		{    
			try
			{	
				var name = document.getElementById("fio").value;
				var adr  = document.getElementById("adres").value;
				var tel1 = document.getElementById("tel1").value;
				var tel2 = document.getElementById("tel2").value;
				var mail = document.getElementById("mail").value;

				var game = "site=1&name=" + name + "&adr=" + adr + "&tel1=" + tel1 + "&tel2=" + tel2 + "&mail=" + mail;
				xmlHttp5.open("POST", "goOrder.php", true); 
				xmlHttp5.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				xmlHttp5.onreadystatechange = requestProc5; 
				xmlHttp5.send(game); 
	 
			}
			catch (e)
			{ 
				alert("Не удалось соединиться с сервером [5]:\n" + e.toString());     
			}   
		}
	}

	function requestProc5()
	{
		if (xmlHttp5)
		{
			if(xmlHttp5.readyState == 4)
			{
				if(xmlHttp5.status==200) 
				{
					document.getElementById("items").innerHTML = "0 шт.";
					document.getElementById("count").innerHTML = "0 грн.";
					document.getElementById("itemsCart").innerHTML = "<center>Ваш заказ #" + xmlHttp5.responseText + " принят.<br><br>В ближайшее время с Вами свяжутся для подтверждения заказа.</center>";
				}
			}
		}
	}

	function delFromCart(id)
	{
		if (xmlHttp6)
		{    
			try
			{	
				var game = "site=1&itemID=" + id;
				xmlHttp6.open("POST", "delFromCart.php", true); 
				xmlHttp6.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				xmlHttp6.onreadystatechange = requestProc6; 
				xmlHttp6.send(game); 
	 
			}
			catch (e)
			{ 
				alert("Не удалось соединиться с сервером [6]:\n" + e.toString());     
			}   
		}
	}

	function requestProc6()
	{
		if (xmlHttp6)
		{
			if(xmlHttp6.readyState == 4)
			{
				if(xmlHttp6.status==200) 
				{
					getItemsCart('1');
				}
			}
		}
	}

	function preLoadImage(img)
	{
		var loadImg = img;
		document.getElementById("itemImage").innerHTML = "<img src=\"images/items/" + loadImg + "\" width=\"250\" height=\"350\" border=\"0\">";
	}

	function checCart()
	{
		var go = true;
		var go1 = true;
		var go2 = true;
		if(document.getElementById("fio").value == ""){ go = false; alert('Поле ФИО обязательно для заполнения.'); }
		if(go)
		{
			if(document.getElementById("adres").value == ""){ go1 = false; alert('Поле Адрес обязательно для заполнения.'); }
			if(go1)
			{
				if(document.getElementById("tel1").value == ""){ go2 = false; alert('Поле Телефон (1) обязательно для заполнения.'); }
				if(go2){
					goOrder();
				}
			}
		}
	}

	function changeSort(type, id)
	{
		var myAjax = new Ajax.Request('sort.php',{ 
			method: 'post',
			parameters: {t: type, id: id},
			onSuccess: function(response){
						var result = response.responseText;
						location.href = '/?cat_id='+id;
					},
			onFailure: function(response){
				var result = response.responseText();
				openAlert(result);
			}
		});
	}
