function addGoodsToCart(goodsID)
{
	var date = new Date();
	var url = "/cart/quick_add/?goods_id=" + goodsID + "&t=" + date.getTime();
	document.getElementById('add_cart_frame').src = url;
	
	return false;
}

function findElementByID(id, win)
{
	// current window
	var w = (win != null) ? win : window; 
	var field = null;
	
	var isFirst = true;
	do
	{
		if (!isFirst)
		{
			w = w.parent;
		}
		field = w.document.getElementById(id);
		isFirst = false;
	}
	while (field == null && w != null && w.parent != null && w != w.top && w.parent.location != w.location);
	
	// Don't found? Get opener window!
	if (field == null && w != null && w.opener != null)
	{
		field = findElementByID(id, w.opener);
	}
	
	return field;
}


////////////////////////////


function cartSubmit(formId)
{
	if (typeof(formId) == 'undefined' || formId == null)
	{
		formId = "cartForm";
	}
	
	pt_delivery = document.getElementById('pt_delivery');
	if (pt_delivery && pt_delivery.checked)
	{
		cartSubstage('delivery_addr');
	}

	document.getElementById(formId).submit();
}
function cartAction(str)
{
	document.getElementById('cartAction').value=str;
	
	if (str == 'goNext')
	{
		document.getElementById('substage').value = step_next_substage;
	}
}
function cartSubstage(str)
{
	document.getElementById('substage').value=str;
}
function cartDeleteGood(goodid,barcode)
{
	cartAction("deleteGoods");
	document.getElementById('cartGoodsId').value = goodid+'_'+barcode;
	cartSubmit();
}
function cartPayBonusButton()
{
	var bonusAmount = document.getElementById('input_pay_bonus').value;
	document.getElementById('pay_bonus').value = bonusAmount;
	cartSubmit();
}
function updateDeliveryAddress(index,addr,comment,phone,contact)
{
	document.getElementById('index').value = index;
	document.getElementById('index_selected').innerHTML = index;
	document.getElementById('new_addr').value = addr;
	document.getElementById('address_selected').innerHTML = addr;
	document.getElementById('comment').value = comment;
	document.getElementById('phone').value = phone;
	document.getElementById('contactName').value = contact;
}
