var prod = new Array("FI","K9","RP","FL","AV");
var itemObj = new Array();
var flg = 0;
var tCost = 0;

function ImportTabItem(){

	itemTabs.activeTab(0);

	petImage1.setImageReference (itemObj[0].imgURL, itemObj[0].imgURL);
	itemLabel1.setText(itemObj[0].itemId);
	descLabel1.setText(itemObj[0].description);
	proLabel1.setText(itemObj[0].productId);
	priLabel1.setText("$"+itemObj[0].price);
	accLabel1.setText(itemObj[0].account);
	if( itemObj.length>1 ){
	petImage2.setImageReference (itemObj[1].imgURL, itemObj[1].imgURL);
	itemLabel2.setText(itemObj[1].itemId);
	descLabel2.setText(itemObj[1].description);
	proLabel2.setText(itemObj[1].productId);
	priLabel2.setText("$"+itemObj[1].price);
	accLabel2.setText(itemObj[1].account);
	}
}

function TabFunc(resultObj){
	
	var tabLen = itemTabs.arrTabItem.length;
	itemTabs.activeTab(0);
	if (tabLen>0){
		for (var i=0;i<tabLen;i++){
			itemTabs.removeTabItem(0);
		}
	}
	
	if (itemObj.length>0){
			for (i=0;i<itemObj.length;i++){
			//tabにデータをロード
			myTabItem1 = itemTabs.addTabItem(itemObj[i].itemId);
			petImage = new rialto.widget.Image("images/"+itemObj[i].imgURL, 10, 10, myTabItem1, "petimage");
			itemLabel = new rialto.widget.Label('accountLabel', 10, 150, myTabItem1, itemObj[i].itemId , 'libelle1');
			descLabel = new rialto.widget.Label('accountLabel', 30, 150, myTabItem1, itemObj[i].description , 'libelle1');
			proLabel = new rialto.widget.Label('accountLabel', 50, 150, myTabItem1, itemObj[i].productId , 'libelita');
			priLabel = new rialto.widget.Label('priceLabel', 70, 150, myTabItem1, "$"+itemObj[i].price , 'libNormal');
			accLabel = new rialto.widget.Label('accountLabel', 140, 10, myTabItem1, itemObj[i].account , 'libNormal');
			addCartButton = new rialto.widget.Button(90, 180, 'add to cart', 'カートボタン', myTabItem1);

			function funcRef(idx){
				return function(){
					var tempTabData = cartGrid.tabData;	
					tCost+=parseInt(itemObj[idx].price);
					totalcCostLabel.setText("$"+tCost);
					flg=0;
					
					for(i=0;i<tempTabData.length;i++){
						if( itemObj[idx].itemId===tempTabData[i][0] ){
							cartGrid.initTab();
							tempTabData[i][3]+=1;
							cartGrid.fillGrid(tempTabData);
							flg=1;
						}
					}
					if( flg==0){
						var petLigne = new Array(itemObj[idx].itemId,itemObj[idx].productId,itemObj[idx].description,1,"$"+itemObj[idx].price);
						cartGrid.addOneLine(petLigne);
					}
					myTabs.activeTab(1);
				}
			}

			addCartButton.onclick=funcRef(i);
		}
	}
	itemTabs.activeTab(0);	
}

function req(param){
  sendxmlText.setValue(param.sendXML);
}
function res(param){
  resxmlText.setValue(param.xhr.responseText);
}
