var arrShopBag = new Array();
var Productlist = new function()
{
	this.Product  = new Array();
	this.Hdisk  = new Array();
	this.Product[0]=new Array("","请选择产品型号",0);
	this.Product[1]=new Array("3.5","BTTV-3型 3.5寸",980);
	//this.Product[2]=new Array("3.5","BTTV-3型 3.5寸",980);
	//this.Hdisk[0]=new Array("2.5","不含硬盘",0);
	//this.Hdisk[1]=new Array("2.5","160G硬盘",400);
	///this.Hdisk[2]=new Array("2.5","250G硬盘",540);
	this.Hdisk[0]=new Array("3.5","不含硬盘",0);
	this.Hdisk[1]=new Array("3.5","160G硬盘",300);
	this.Hdisk[2]=new Array("3.5","250G硬盘",400);
	this.Hdisk[3]=new Array("3.5","500G硬盘",580);
}

function SelectProduct (box,boxmoney,hd,hdmoney,num)
{
	this.ProductBox = box;
	this.ProductHdisk = hd;
	this.ProductNum = parseInt(num);
	this.ProductBorn = parseInt(boxmoney) + parseInt(hdmoney);
	this.ProductMoney = this.ProductBorn * this.ProductNum;
}

function oShopBag ()
{
	this.DelItem = function (x)
	{
		if (x < 0 || x > arrShopBag.length ){return false;}
		for(var ii=0;ii<arrShopBag.length;ii++)
		{
			if(ii > x)
			{
				arrShopBag[ii-1]=arrShopBag[ii];
			}
		}
		if (arrShopBag.length > 0)
		{
			arrShopBag.length -= 1;
		}
	}

	this.AddItem = function (box,hd,num)
	{
		if (box == "" || hd == "" || num == "" || num == "0" )
		{
			alert("请选择好产品并填写好数量后再加入购物车!");
			return false;
		}
		var boxtitle , boxmoney ,hdtitle , hdmoney ;
		for (var ii=0 ; ii<Productlist.Product.length ; ii++ )
		{
			if (ii == box)
			{
				boxtitle = Productlist.Product[ii][1];
				boxmoney = Productlist.Product[ii][2];
			}
		}
		for (var ii=0 ; ii<Productlist.Hdisk.length ; ii++ )
		{
			if (ii == hd)
			{
				hdtitle = Productlist.Hdisk[ii][1];
				hdmoney = Productlist.Hdisk[ii][2];
			}
		}

		var p = new SelectProduct(boxtitle,boxmoney,hdtitle,hdmoney,num);
		arrShopBag[arrShopBag.length] = p;
	}

	this.ReturnHtml = function ()
	{
		var htmlbody = "";
		for(var ii=0;ii<arrShopBag.length;ii++)
		{
			htmlbody += "<div class='prodbox'><INPUT TYPE='text' NAME='product' value='" + arrShopBag[ii].ProductBox + "' size=18 readOnly='false'></span>";
			htmlbody += "<span class='prodhd'><INPUT TYPE='text' NAME='hdisk' value='" + arrShopBag[ii].ProductHdisk + "' size=18 readOnly='false'></span>";
			htmlbody += "<span class='prodnum'><INPUT TYPE='text' NAME='productnum' value='" + arrShopBag[ii].ProductNum + "' size=10 readOnly='false'></span>";
			htmlbody += "<span class='prodborn'><INPUT TYPE='text' NAME='prodborn' value='" + arrShopBag[ii].ProductBorn +"' size=10 readOnly='false'></span>";
			htmlbody += "<span class='prodmoney'><INPUT TYPE='text' NAME='prodmeney' value='" + arrShopBag[ii].ProductMoney + "' size=10 readOnly='false'></span>";
			htmlbody += "<span class='prodop'><a href='javascript:delectprod(" + ii + ");'>删除</a></div>";
		}
		return htmlbody;
	}

	this.SumMoney = function ()
	{
		var sum = 0;
		for(var ii=0;ii<arrShopBag.length;ii++)
		{
			sum += arrShopBag[ii].ProductMoney;
		}
		return sum;
	}
}
