var MealDealPanel = Class.create(Panel, {
    initialize: function ($super, passportReference, tridionPanelId, panelPosition) {
		$super(passportReference, tridionPanelId);
		this.panelId = 'MealDeal';
		this.panelPosition = panelPosition;
		this.strParams = [];
		this.classPrefix = 'md';
    },
    doWork: function () {
		this.adultInput = this.panelHTML.select('[name=inputAdultQuantity]')[0];
		this.childInput = this.panelHTML.select('[name=inputChildQuantity]')[0];
		this.cupInput = this.panelHTML.select('[name=inputCupQuantity]')[0];
		
		this.__setupInput(this.adultInput);
		this.__setupInput(this.childInput);
		this.__setupInput(this.cupInput);
		
		var bt = this.panelHTML.select('.park2Table')[0];
		
		if (bt != undefined) {
			this.mdData = this.__filterDataGroupByProperty(this.data.ListMealDeal, 'Description');
			this.__generateRowsFor2Prices('dp1', 'productVariantCatalog', this.mdData, bt, this.adultInput, this.childInput);
		}

		var cupPrice = this.panelHTML.select('[id=zipCupPrice]')[0];
		if (cupPrice != undefined) cupPrice.update('$' + (parseFloat(this.data.ListSouvenirCup[0].Price)).toFixed(2));

		this.__setupAddToCart();
		this.__loadValues(['text/inputAdultQuantity', 'text/inputChildQuantity', 'radio/productVariantCatalog', 'text/inputCupQuantity']);
    },
	_calculateTotalPrices: function() {
		this.__generateTotalPrice2Prices('dp1', this.mdData, this.adultInput, this.childInput);
	},
	_formatDataAndSend: function (data) {
		var ppqc = data.productVariantCatalog.split('|');
		var cup = this.data.ListSouvenirCup[0];
		var cupQuantity = jsHelper.toInt($F(this.panelHTML.select('[name=inputCupQuantity]')[0]));
		var dataFormatted = {
			productID: ppqc[0] + "|" + ppqc[1] + "|" + cup.ProductId,
			productVariantID: ppqc[2] + "|" + ppqc[3] + "|" + cup.ProductVariantId,
			qty: data.inputAdultQuantity + "|" + data.inputChildQuantity + "|" + cupQuantity,
			catalogName: ppqc[4] + "|" + ppqc[5] + "|" + cup.VirtualCatalog
		};
		this.passportReference.addToCart(dataFormatted);
    },
    _validateInputData: function (data) {
		var adultQuantity = jsHelper.toInt(data.inputAdultQuantity);
		var childQuantity = jsHelper.toInt(data.inputChildQuantity);
		return (data.productVariantCatalog != undefined && (adultQuantity > 0 || childQuantity > 0));
    }
});
