/*global Class, Classes, _e, _v, _xn, _xv, addClass, addEvent, ajax, hasClass, hide, preventDefault, removeClass, show, showMessage, window*/

Classes.Promo = new Class();
Classes.Promo.prototype = {	
	koszyk: null,
	__construct: function (params) {
		this.copy(params);
	},
	
	decode: function (root,method) {		
		var type = root['msgType'];
		var options = root['msgOptions'] || {};
		
		delete root['msgType'];
		switch(type) {
		case 'info':
			this.infoMessage(root,method,options);
			return options['return']!==undefined ? options['return'] : false;
		case 'yesno':
			this.yesnoMessage(root,method,options);
			return options['return']!==undefined ? options['return'] : false;
		}
		return false;
	},
	
	infoMessage: function(root,method,options) {
		switch(method) {
		case 'setAmount':
			$("#input_amount_"+options['bid']).val(options['amount']);
			break;
		}
		showMessage(root['msgText']);
	},
	
	yesnoMessage: function(root,method,options) {			
		switch(method) {
		case 'removeProduct':
			LightBox.showYesNo(root['msgText'], 'koszyk.usunKoszykPozycja('+options['bid']+', 1);');
			break;
		case 'checkRemoveProduct':
			LightBox.showYesNo(root['msgText'], 'koszyk.przeniesKoszykSchowekPozycja('+this.bid+','+this.pid+', false);');
			break;
		case 'checkRemoveProductPrezent':
			LightBox.showYesNo(root['msgText'], 'koszyk.przeniesPrezentKoszykSchowekPozycja('+this.bid+','+this.pid+', false);');
			break;
		case 'checkDoKasy':
			LightBox.showYesNo(root['msgText'], 'window.location = \''+options['link']+'\';','window.location = \'koszyk_potwierdz.php\';');
			break;
		case 'setAmount':
			LightBox.showYesNo(root['msgText'], 'koszyk.setAmountOfProduct('+this.bid+','+this.amount+', 1);','$("#input_amount_'+options['bid']+'").val('+options['amount']+');');			
			break;			
		case 'addProduct':
			if(options['czytnik'])
				LightBox.showYesNo(root['msgText'], 'koszyk.dodajKoszyk('+options['pid']+',1,0,0,null,1);');
			else
				LightBox.showYesNo(root['msgText'], 'window.location = \''+options['link']+'\';');
			break;
		default:
			LightBox.showYesNo(root['msgText'], 'window.location = \''+options['link']+'\';');
			break;
		}
	}
};



