Ext.define('TradePortal.controller.Payaccount', {
	extend : 'Ext.app.Controller',

	stores : [ ],

	views : [ 'payaccount.Panel', 'account.InfoView' ],

	models : [ ],

	init : function() {
		if (typeof console !== "undefined") {
			console.log('Initialized Payaccount!');
		}

		this.control({
			'viewport > panel' : {
				render : this.onPanelRendered
			},
			'payaccountpanel' : {
				show : this.onButtonRendered
			}
		});
	},
	onPanelRendered : function() {
		if (typeof console !== "undefined") {
			console.log('Payaccount panel was rendered');
		}		
	},
	onButtonRendered : function() {
		Ext.get("paypal_button").update('<form name="_xclick" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_xclick"><input type="hidden" name="business" value="'+Ext.getStore('Config').data.last().data.paypal_email+'"><input type="hidden" name="currency_code" value="'+Ext.getStore('Config').data.last().data.paypal_currency_code+'"><input type="hidden" name="item_name" value="'+Ext.getStore('Config').data.last().data.paypal_product_name+'"><input type="hidden" name="amount" value="'+Ext.getStore('Config').data.last().data.paypal_amount+'"><input type="hidden" name="tax" value="'+(Ext.getStore('Config').data.last().data.paypal_amount*Ext.getStore('Config').data.last().data.paypal_tax/100).toFixed(2)+'"><input type="image" src="https://www.paypalobjects.com/en_AU/i/btn/btn_paynow_LG.gif" border="0" name="submit"><input type="hidden" name="add" value="1"></form>');
	    Ext.getCmp("paypal_amount").setValue(Ext.getStore('Config').data.last().data.paypal_amount);
    }
});