function changeprintbox(obj, type_id, item_id, nk_id) {
	if (nk_id == undefined) {
		nk_id = 0;
	}
	if (_eval('chkbox'+obj).checked == true) {
		addingCartElement(obj, type_id, item_id, nk_id);
	} else {
		deletingCartElement(obj, type_id, item_id);
	}
}

function addToCartFromExt(obj, type_id, item_id, nk_id) {
	if (nk_id == undefined) {
		nk_id = 0;
	}
	addingCartElement(obj, type_id, item_id, nk_id);
}


function addingCartElement(obj, type_id, item_id, nk_id) {
	_eval('box'+obj).style.display = 'none';
	_eval('adding'+obj).style.display = 'block';
	var req = new JsHttpRequest();
	req.onreadystatechange = function() 
	{
		if (req.readyState == 4)
		{
			if (req.responseJS) {
				_eval('adding'+obj).style.display = 'none';
				_eval('box'+obj).style.display = 'block';
				_eval('chkbox'+obj).checked = req.responseJS.status;
				recountCart()
			}
	    }
	}
    req.open('POST', 'http://' + document.location.hostname + '/webz2/ajax.php', true);
    req.send({f: "addCEl",type: type_id, item: item_id, nk:nk_id});
}

function deletingCartElement(obj, type_id, item_id) {
	_eval('box'+obj).style.display = 'none';
	_eval('deleting'+obj).style.display = 'block';
	var req = new JsHttpRequest();
	req.onreadystatechange = function() 
	{
		if (req.readyState == 4)
		{
			if (req.responseJS) 
			{
				_eval('deleting'+obj).style.display = 'none';
				_eval('box'+obj).style.display = 'block';
				_eval('chkbox'+obj).checked = req.responseJS.status;
				recountCart()
			} 
		}
	}
    req.open('POST', 'http://' + document.location.hostname + '/webz2/ajax.php', true);
    req.send({f: "delCEl",type: type_id, item: item_id});
}

function deletingFromCart(block_id, type_id, item_id) {
	_eval('box'+block_id).style.display = 'none';
	_eval('deleting'+block_id).style.display = 'block';
	var req = new JsHttpRequest();
	req.onreadystatechange = function() 
	{
		if (req.readyState == 4)
		{
			if (req.responseJS) 
			{
				_eval(block_id).style.display = "none";
				recountCart();
			}
	    }
	}
    req.open('POST', 'http://' + document.location.hostname + '/webz2/ajax.php', true);
    req.send({f: "delCEl",type: type_id, item: item_id});
}

function recountCart() {
	var req = new JsHttpRequest();
	req.onreadystatechange = function() 
	{
		if (req.readyState == 4)
		{
			if (req.responseJS) 
			{
				counts = req.responseJS.count;
				var zeros = 0;
				var allItems = 0;
				for (var i = 1; i <= 3; i++) {
					if (counts[i] == 0) {
						if (_eval('sign'+i)) {
							_eval('sign'+i).style.display = 'none';
						}
						if (_eval('typeBlock'+i)) {
							_eval('typeBlock'+i).style.display = 'none';
						}						
						zeros++;
					} else {
						if (_eval('sign'+i)) {
							_eval('sign'+i).innerHTML = eval('typeSign'+i) + ' (' + counts[i] + ')';
						}
						allItems = allItems+eval(counts[i]);
					}
				}
				if (zeros == 3) {
					if (_eval('noElements')) {
						_eval('noElements').style.display = 'block';
					}
					if (_eval('cartItems')) {
						_eval('cartItems').innerHTML = "Корзина печати";
						_eval('cartItems').href = '#';
					}
				}
				if (allItems > 0) {
					_eval('cartItems').innerHTML = "Корзина печати ("+allItems+")";
					_eval('cartItems').href = "?page=10";
				}
			}
	    }
	}
    req.open('POST', 'http://' + document.location.hostname + '/webz2/ajax.php', true);
    req.send({f: "count"});
}