function ajax_query(query,onExecute) {
	// создаем и загружаем обьект для подгрузки данных
	var req = null;
	// Mozilla, Safari, ...
	if (window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
		if (req.overrideMimeType)
		{
			req.overrideMimeType('text/plain');
		}
	}
	else if (window.ActiveXObject)
	{ // IE
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	// callback-функция при получении данных
	req.onreadystatechange = function()
	{
		// если данные уже есть
		if(req.readyState == 4)
		{
			onExecute(req.responseText,req.status,req.statusText);
		}
	}
	req.open("GET", query, true);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
	// запрашиваем данные
	req.send(null);
}

function loadPrice (catid) {
	if (document.getElementById('pricelist'+catid+'content').innerHTML=='') {
		document.getElementById('pricelist'+catid+'content').innerHTML = '<div align=center><img src=_images/ajax-loader.gif></div>';
		ajax_query(
		'ajaxpriceview.html?filterTypeId='+document.getElementById('filterTypeId').value+'&filterCategoryId='+document.getElementById('filterCategoryId').value+'&price_for='+catid,
		function (resp,status,text) {
			document.getElementById('pricelist'+catid+'content').innerHTML = resp;
		}
		);
	}
	document.getElementById('pricelist'+catid).style.visibility = 'visible';
	document.getElementById('pricelist'+catid).style.display = 'block';
	document.getElementById('desccat'+catid).style.visibility = 'hidden';
	document.getElementById('desccat'+catid).style.display = 'none';
	document.getElementById('poscount'+catid).className = 'statistic2';
	document.getElementById('showprice'+catid).className = 'img_caption2';
	document.getElementById('categorycaption'+catid).className = 'caption2';
	document.getElementById('arrow'+catid).style.visibility = 'visible';
	document.getElementById('arrow'+catid).style.display = 'block';
	return false;
}

function closePrice(catid) {
	document.getElementById('pricelist'+catid).style.visibility = 'hidden';
	document.getElementById('pricelist'+catid).style.display = 'none';
	document.getElementById('desccat'+catid).style.visibility = 'visible';
	document.getElementById('desccat'+catid).style.display = 'block';
	document.getElementById('poscount'+catid).className = 'statistic';
	document.getElementById('showprice'+catid).className = 'img_caption';
	document.getElementById('categorycaption'+catid).className = 'caption';
	document.getElementById('arrow'+catid).style.visibility = 'hidden';
	document.getElementById('arrow'+catid).style.display = 'none';
	return false;
}


function calc (basketid,pos,cnt,posid,sumid) {
	ajax_query("ajaxbasket.html?cost_for_position="+pos+"&cnt="+cnt,function (resp,status,text) {
		document.getElementById(posid).innerHTML = resp;
		ajax_query("ajaxbasket.html?sum_for_basket="+basketid,function (resp,status,text) {
			document.getElementById(sumid).innerHTML = "Суммарная стоимость: "+resp;
		});
	});
}

function clearBasket () {
	document.getElementById('basket_div').innerHTML = '<div align=center><img src=_images/ajax-loader.gif></div>';
	ajax_query("ajaxbasket.html?clear=1",function (resp,status,text) {
		document.getElementById("basket_div").innerHTML = resp;
	});
	return false;
}


var positionInSelect = 0;

function getAnalogs (id) {
	positionInSelect = id;
	ajax_query("ajax_analogs.html?posid="+id,function (resp,status,text) {
		document.getElementById("analogs").innerHTML = resp;
	});
}

function addAnalog () {
	var analogs = document.getElementById('list2');
	var adding = '';
	x = 0;
	for (var i=0; i < analogs.options.length; i++) {
		if (analogs.options[i].selected) {
			adding = adding + "&add"+x+"="+analogs.options[i].value;
			x++;
		}
	}
	ajax_query("ajax_analogs.html?"+adding+"&posid="+positionInSelect,function (resp,status,text) {
		document.getElementById("analogs").innerHTML = resp;
	});
}

function delAnalog () {
	var analogs = document.getElementById('analogs');
	var deling = '';
	x = 0;
	for (var i=0; i < analogs.options.length; i++) {
		if (analogs.options[i].selected) {
			deling = deling + "&del"+x+"="+analogs.options[i].value;
			x++;
		}
	}
	ajax_query("ajax_analogs.html?"+deling+"&posid="+positionInSelect,function (resp,status,text) {
		document.getElementById("analogs").innerHTML = resp;
	});
}