/*AVP Trolley Module */

var bag = new makearray2d (51,3);
var bagpos;
bagpos=1;
var bagtot=0.00;

function makearray2d (X,Y)
	{
	var count;
	this.length=X;
	for (var count=1;count<=X;count++)
		this[count] =new makearray(Y);
	}

function makearray (numelements)
	{
	var count;
	this.length=numelements;
	for (count=1;count<=numelements;count++)
		this[count]=0;
		return (this);
	}

function bagit(p,t,c)
	{
/*swgfl*/
if (whoisit=="site=swgfl2701")
{
	p=p.replace("W05","SG05");
}

/***********/
	var f,g,h;
	bag [bagpos] [1] = p;
	bag [bagpos] [2] = t;
	bag [bagpos] [3] = c;
	bag [bagpos] [4] = "1";
	
	bagpos++;
	bagcount();/*update status*/
	if(bagpos==51)
	{
	alert("Your bag is full. Wow! You need to order and then refresh to empty it before adding any more items.");
	bagpos=50;
	}
alert("You have added a \r\n" + t + "\r\nversion of product\r\n" + p + "\r\nto your trolley");
	}

function bagcount()
	{

	var items,tvalue;
	items=0;
	tvalue=0;
	for (q=1;q<bagpos;q++)
	{
		items+=Number(bag [q] [4]);
		tvalue+=Number(bag [q] [4])*(Number(bag [q] [3]));
	}


	/*  var whichdoc=top.banner.document;  */
	var theob = document.getElementById('bagstatus');
	var stat="<p align=\"center\" class=\"normal\">Items: ";
	stat+=items;
	stat+="</p><p align=\"center\" class=\"normal\">Value: &pound;";
	bagtot=tvalue;
	stat+=bagtot.toFixed(2);
	stat+="</p>";
	theob.innerHTML=stat;

	}

function trash(item)
	{
	var j;
	c=0-Number(bag [item] [3]);
	for (j=item;j<bagpos;j++)
		{
		bag [j] [1]	=bag [j+1] [1];
		bag [j] [2]	=bag [j+1] [2];
		bag [j] [3]	=bag [j+1] [3];
		bag [j] [4]	=bag [j+1] [4];
		}
	bagpos--;
	bagcount();
	theframe.location="trolley.htm";
	}
