var App = function() {
	var self = this;
	self.init = function (params) {
		if(params.name)
			$('#name').text(' ' + params.name);
		
		$('#BuyButton').unbind().click(function () {
			yasoon.license.openPurchaseWindow(6, function () {
				//Close Handler
				yasoon.license.getActiveProducts(function (products) {
					if (products && products.length > 0) {
						var data = yasoon.setting.getAppParameter('data');
						if (data) {
							data = JSON.parse(data);
							data.license = products[0];
							data.license.validUntil = new Date(data.license.validUntil);
							yasoon.setting.setAppParameter('data', JSON.stringify(data));
							
							if (data.license.validUntil > new Date()) {								
								yasoon.dialog.showMessageBox('Please restart Outlook to re-activate Wunderlist!');
							}
						}
					}
				});
			});
			return false;
		});
	};
};

if(window.yasoon) {
	yasoon.dialog.load(new App());
}
else {
	window.app = new App();
	window.app.init();
}