var SysClose = (function(){
	$('.softLogo').dblclick(function(){
		if(!pur5.Cfg.pur5Uid) window.close();
		pur5.Pages.alert($('#sysClose')[0]);
	});
	$('.signOutBtn, .closeSoftBtn').click(function(){
		if(!pur5.Cfg.pur5Uid) window.close();
		pur5.Pages.alert($('#sysClose')[0]);
	});
	
	$('#pur5TopMenu a:contains(\'退出系统\')').live('click', function(){
		$('.signOutBtn').triggerHandler('click');
	});
	return {
		init: function(){
			var self = this;
			$('#sysCloseBtn').click(function(){
				self.close();
			});
		},
		close: function(){
			var arr = [
					pur5.Cfg.sysInterval,
					pur5.Cfg.sysPopInterval,
					pur5.Cfg.sysRunTimeInterval,
					pur5.Cfg.ReadTBOrdersInterval,
					pur5.Cfg.TBSendOrdersInterval,
					pur5.Cfg.TBReDeliverInterval,
					pur5.Cfg.ReadPPOrdersInterval,
					pur5.Cfg.sysUserMoneyInterval
				];
			for(var i = 0, l = arr.length; i < l; i++) {
				clearInterval(arr[i]);
			}
			
			UI.immovable();
			$.get(pur5.Cfg.GBHOSTSOFT + 'logout.asp', {token: pur5.Cfg.token});
			
			pur5.Cfg.FSTray = pur5.Cfg.pur5Ax = pur5.Cfg.Ds = null;
			CollectGarbage();
			
			//pur5.Pages.clearSnap();
			window.close();
		}
	}
})();
$(function(){
	SysClose.init();
});