/* DELETED */
function Add2CartOne(prodid,bar_code,subcat,frame)
{
        var url="../add2cart.php?prodid="+prodid+"&bar_code="+bar_code+"&amount=1&subcat="+subcat;
        if (frame)
        {
                url += "&frame";
                window.parent.document.getElementById('frame1').src=url;
        } else document.getElementById('frame1').src=url;
}

/* DELETED */
function Add2Cart(prodid,bar_code)
{
	amount=document.getElementById("g"+prodid+"_"+bar_code).value;
	if(amount=="") amount=1;
	var url="../add2cart.php?prodid="+prodid+"&bar_code="+bar_code+"&amount="+amount;
	document.getElementById('frame2').src=url;
}

/* DELETED */
function Add2CartB2B(prodid,bar_code,doc_id)
{
	amount=document.getElementById("g"+prodid+"_"+bar_code).value;
	if(amount=="") amount=1;
	var url="/b2b/add2cart.php?prodid="+prodid+"&bar_code="+bar_code+"&amount="+amount+"&doc_id="+doc_id;
	document.getElementById('frame2').src=url;
}

/* DELETED */
function Add2CartFrame(prodid,bar_code,subcat)
{
	var win;
	if (GetCookie('perrectumadastra')!=17)
	{
		win=window.open("dummyadd.php?prodid="+prodid+"&bar_code="+bar_code+"&subcat="+subcat,"",
			"width=150, height=40, top="+(screen.height/2-30)+", left="+(screen.height/2-30)+",resizable=0");
	}
	else
	{
		win=window.open("dummyadd.php?prodid="+prodid+"&bar_code="+bar_code+"&subcat="+subcat,"",
			"width=150, height=40, resizable=0");
	}
}

function AddGoods2CartOne(siteUrl, goodsID, barcode, subcat)
{
	AddGoods2Cart(siteUrl, goodsID, barcode, 1, subcat);
}

function AddGoods2CartB2B(siteUrl, goodsID, barcode, amount, doc_id)
{
	var url = siteUrl + "add2cart.php?prodid="+goodsID+"&bar_code="+barcode+"&amount="+amount+"&doc_id=" + doc_id;

	var frame = findElementByID('add_cart_frame');
	if (frame != null)
	{
		frame.src = url;
	}
}

function AddGoods2Cart(siteUrl, goodsID, barcode, amount, subcat)
{
	var url = siteUrl + "common/add2cart.php?prodid="+goodsID+"&bar_code="+barcode+"&amount="+amount+"&subcat="+subcat;

	var frame = findElementByID('add_cart_frame');
	if (frame != null)
	{
		frame.src = url;
	}
}

function ClearCart()
{
	window.open("clearcart.php","ClearCart","width=10,height=10");
}

function UpdateCart(prodid)
{
	amount=document.getElementById("g"+prodid).value;
	document.updateform.amnt.value=amount;
	document.updateform.goodid.value=prodid;
	document.updateform.submit();
}

function UpdateAll(updates)
{
	var goods, amounts, moneybacks,insurances;
	goods=""; amount=""; moneybacks=""; insurances="";
	for (i = 0; i < updates.length; ++i)
	{
		goods=goods+updates[i]+",";
		amount=amount+document.getElementById("g"+updates[i]).value+",";
		if (document.getElementById("gmb"+updates[i]) != null)
		{
			moneybacks=moneybacks+document.getElementById("gmb"+updates[i]).value+",";
		}
		if (document.getElementById("gin"+updates[i]) != null)
		{
			insurances=insurances+document.getElementById("gin"+updates[i]).value+",";
		}
	}

	document.forms['updateform'].amnt.value=amount;
	document.forms['updateform'].goods.value=goods;
	if (document.forms['updateform'].moneybacks != null)
	{
		document.forms['updateform'].moneybacks.value=moneybacks;
	}
	if (document.forms['updateform'].insurances != null)
	{
		document.forms['updateform'].insurances.value=insurances;
	}
	document.forms['updateform'].submit();
}

function getCookieVal (offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	{
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)
			break;
	}
	return null;
}

function add_good(good_id)
{
    var top_doc=window.parent.opener.parent.document;
    var wh_select=top_doc.getElementById('warehouse_reserve');
    var wh_id=wh_select.options[wh_select.selectedIndex].value;
    var doc_id=top_doc.getElementById('doc_id').value;
    window.open(
        'add_good.php?good_id='+good_id+'&warehouse_id='+wh_id+'&doc_id='+doc_id+'&pickup=1','',
        "width=170, height=40, top="+(screen.height/2-30)+", left="+(screen.height/2-30)+",resizable=0");
}

