function addToCart(good, form) {
	var amount = 1,
		tpl = '';

	try {
		for (var i = 0; i < form.length; i++) 
			if (form.elements[i].name == 'amount[' + good + ']') 
				amount = form.elements[i].value;
	}
	catch (e) {}

	try {
		tpl = document.getElementById('cart_tpl').value;
	}
	catch (e) {}

	var xmlHttp = getXmlHttpObject();

	if (!xmlHttp) 
		return true;

	xmlHttp.open('GET', 'modules/goods_cart/addtocart.php?good=' + good + '&amount=' + amount +'&tpl=' + tpl, true);
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			try {
				var xmlDoc = xmlHttp.responseXML.documentElement;
			}
			catch (e) {
				alert('Ошибка при обработке запроса.');
			}

			try {
				var amount = xmlDoc.getElementsByTagName('amount')[0].childNodes[0].nodeValue;
				var summ = xmlDoc.getElementsByTagName('summ')[0].childNodes[0].nodeValue;

				document.getElementById('cart_amount').innerHTML = amount;
				document.getElementById('cart_summ').innerHTML = summ;
			}
			catch (e) {}

			try {
				addedToCart(form.action);
			}
			catch (e) {
				confirm('Выбранный товар добавлен в корзину.\nПерейти к оформлению заказа?') ? window.location.assign(form.action) : null;
			}
		}
	}
	xmlHttp.send(null);

	return false;
}

function validAmount(field) {
	var value = field.value;
	var set = !isNaN(value) && parseInt(value, 10) > 0 ? parseInt(value, 10) : 0;

	if (set > 10000)
		set = 10000;
	if (set < 0)
		set = 0;

	field.value = set;
}