var 	cartItem;
var	cartQInput;
var 	qForm;

function addToCart()
{
//	if( ! (cartQInput = document.getElementById("cart_"+id) ) )
	if( ! cartItem || ! cartQInput )
		return false;
	var cartQ = parseInt(cartQInput.value);
	if( 0 >= cartQ )
	{
		alert("Неверное значение!");
		return false;
	}
	var referer = encodeURI(window.location.href);
	window.location.href="/catalog/cart.php?id="+cartItem+"&q="+cartQ+"&referer="+referer;
}

function closeCartInput()
{
	if( qForm )
		qForm.style.display = "none";
}

function showQForm( id, oldValue )
{
	qForm = document.getElementById("dCartInputBox");
	cartQInput = document.getElementById("iCartQ");
	cartQInput.value = oldValue;
	// set global var cartItem
	cartItem = id;
	if (window.innerWidth)
	{
		// DOM window attributes
		var qw = (window.innerWidth >> 1) - 100 + window.pageXOffset;
		var qh = (window.innerHeight >> 1) - 100 + window.pageYOffset;
	}
	else if (document.body.clientWidth)
	{
		// IE attributes
		var qw = (window.screen.availWidth >> 1) - 100;
		var qh = (window.screen.availHeight >> 1) - 100;
		window.scrollTo(0,0);
	}
	if( qw < 0 )
		qw = 0;
	if( qh < 0 )
		qh = 0;

	qForm.style.left = qw+"px";
	qForm.style.top = qh+"px";
	qForm.style.display = "block";
	return false;
}
