Ext.ns('Fecsp.surf.base');

Fecsp.surf.base.Home = Ext.extend(Ext.Panel, {
	initComponent: function() {		
		Ext.apply(this, {		
			header: false,
			border: false,
			height: 800,
			cls: 'home',
			layout: 'border',
			defaults: {
				border: false
			},
			items: [{
				height: 34,
				region: 'north',
				bodyCssClass: 'header-ct',
				layout: 'vbox',
				layoutConfig: {
					align: 'center'
				},
				items: [{
					flex: 1,
					xtype: 'home-header'
				}]
			}, {
				region: 'center',
				bodyCssClass: 'content',
				layout: 'vbox',
				layoutConfig: {
					align: 'center'
				},
				defaults: {
					border: false,
					width: 1000
				},
				items: [{
					xtype: 'flash',
					width: 1000,
					height: 496,					
					flashParams: {
						id: 'homeMovie'
					},				
					url: getOrdinaryPath('/fecsp/surf/base/styles/default/flash-movies/home-movie.swf')					
				}, {
					height: 170,
					xtype: 'box',
					autoEl: {
						tag: 'table',
						border: 0,
						cellSpacing: 0,
						cellPadding: 0,
						style: 'width:100%; height:100%;',
						children: [{
							tag: 'tr',
							children: [{
								tag: 'td',
								html: '网上营业厅为广大客户提供：业务办理、业务缴费、停电信息、电费缴费等服务，用户可通过网上自助办理..　<a href="javascript:void(0);" class="entrance">进入>></a>',
								vAlign: 'top',
								cls: 'module maketing-hall-module'
							}, {
								tag: 'td',
								html: '企业信息公开将发布天津市电力公司最新的新闻动态，以及各项政策法规、资费标准、用电须知等非常丰富的信息..　<a href="javascript:void(0);" class="entrance">进入>></a>',
								vAlign: 'top',
								cls: 'module information-publication-module'
							}, /*{
								tag: 'td',
								html: '通过互动的方式向您展示公司的发展历程、智能家居的概念和用途、用电的锦囊妙招，以及最新业务的展示..　<a href="javascript:void(0);">进入>></a>',
								vAlign: 'top',
								cls: 'module exhibition-hall-module'
							}*/,{
								tag: 'td',
								html: '智能用能管理系统构建智能小区、智能楼宇、智能工业用户的一体化管理平台，提供能效监测、节能分析、双向互动..　<a href="javascript:void(0);" class="entrance">进入>></a>',
								vAlign: 'top',
								cls:  'module intelligent-use-module'
							}]
						}]
					}
				}, {
					height: 100,
					xtype: 'home-footer'
				}]
			}]
		});
		Fecsp.surf.base.Home.superclass.initComponent.apply(this, arguments);
	},
	afterRender: function() {
		Fecsp.surf.base.Home.superclass.afterRender.apply(this, arguments);
		var root = this.get(1).get(1).el.dom;
		var moduleLinks = Ext.DomQuery.jsSelect('a', root);
		var options = {
			preventDefault: true
		};
		Ext.fly(moduleLinks[0]).on('click', this.enterMarketingHall, this, options);
		Ext.fly(moduleLinks[1]).on('click', this.enterInformationPublication, this, options);
		//Ext.fly(moduleLinks[2]).on('click', this.enterExhibitionHall, this, options);
		Ext.fly(moduleLinks[2]).on('click', this.enterIntelligentUse, this, options);
		
		/**var bulletionWin = new Fecsp.surf.base.BulletionWindow();
		bulletionWin.x = document.body.clientWidth - 405;
		bulletionWin.y = document.body.clientHeight - 305;
		//bulletionWin.show();
		
		bulletionWin.on('beforecollapse', function(p) {
			bulletionWin.setPosition(document.body.clientWidth-405, document.body.scrollTop+document.body.clientHeight-25);
		});
		bulletionWin.on('expand', function(p) {
			bulletionWin.setPosition(document.body.clientWidth-405, document.body.scrollTop+document.body.clientHeight-305);
		});
		window.onscroll = function() {
			scrollTop=document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop;
			if (bulletionWin.isVisible() && !bulletionWin.collapsed) {
				bulletionWin.setPosition(document.body.clientWidth-405, scrollTop+document.body.clientHeight-305);
			} else if (bulletionWin.isVisible() && bulletionWin.collapsed) {
				bulletionWin.setPosition(document.body.clientWidth-405, scrollTop+document.body.clientHeight-25);
			}
		}
		window.onresize = window.onscroll;
		**/
	},
	enterMarketingHall: function() {
		window.location.href = getOrdinaryPath('/fecsp/surf/base/marketingHallHome.do?action=carryout');
	},
	enterInformationPublication: function() {
		window.location.href = getOrdinaryPath('/fecsp/surf/infopublic/main.do?action=carryout');
	},
	enterExhibitionHall: function() {
		window.location.href = getOrdinaryPath('/fecsp/surf/base/exhibitionHallHome.do?action=carryout');
	},
	enterIntelligentUse: function() {
		if(ENERGY_HOME == null || ENERGY_HOME == '' || ENERGY_HOME == 'null') {
			Ext.Msg.alert('提示', '智能用能系统暂不可用');
		}else {
			window.location.href = ENERGY_HOME;
		}
	}
});

Fecsp.surf.base.Home.Header = Ext.extend(Ext.BoxComponent, {
	tpl: new Ext.XTemplate(
		'<table cellspacing="0" cellpadding="0" border="0" style="height:100%;">',
			'<tr>',
				'<td class="link-ct"><a href="javascript:void(0);">怀旧风格</a></td>',
				'<td class="link-ct link-separator"><a href="javascript:void(0);">手机版</a></td>',
				'<td class="link-ct link-separator"><a href="javascript:void(0);">关于我们</a></td>',
				'<td class="link-ct link-separator"><a href="javascript:void(0);">设为首页</a></td>',
				'<td class="link-ct link-separator"><a href="javascript:void(0);">添加收藏</a></td>',
				'<td class="link-ct link-separator"><a href="javascript:void(0);">RSS订阅</a></td>',
				'<td class="link-ct link-separator"><a href="javascript:void(0);">下载中心</a></td>',
				'<td class="link-ct link-separator"><a href="javascript:void(0);">友情链接</a></td>',				
				'<td class="search-ct">',
					'<input type="text" name="keywords">',
					'<input type="button" name="btnSearch" value="搜索">',
				'</td>',
			'</tr>',
		'</table>',
		{
			compiled: true,
			disableFormats: true
		}
	),
	data: {},
	initComponent: function() {
		Ext.apply(this, {
			cls: 'header',
			width: 1000			
		});
		Fecsp.surf.base.Home.Header.superclass.initComponent.apply(this, arguments);
	},
	bindActions: function() {
		if (this.rendered) {
			var options = {
				preventDefault: true
			};			
			var links = Ext.DomQuery.jsSelect('a', this.el.dom);
			Ext.fly(links[0]).on('click', this.go2OldHome, this, options);
			Ext.fly(links[1]).on('click', this.go2MblHome, this, options);
			Ext.fly(links[2]).on('click', this.openAboutUs, this, options);
			Ext.fly(links[3]).on('click', this.setAsHomePage, this, options);
			Ext.fly(links[4]).on('click', this.addToBookmarks, this, options);
			Ext.fly(links[5]).on('click', this.doRSS, this, options);
			Ext.fly(links[6]).on('click', this.openDownloadCenter, this, options);
			Ext.fly(links[7]).on('click', this.openFriendshipLink, this, options);
			var bSearch = Ext.DomQuery.selectNode('input[type=button]', this.el.dom);
			Ext.fly(bSearch).on('click', this.doSearch, this);			
		}
	},
	afterRender: function() {
		Fecsp.surf.base.Home.Header.superclass.afterRender.apply(this, arguments);
		this.bindActions();
	},
	openAboutUs: function() {
		//window.location.href=(CONTEXT_PATH + "/fecsp/surf/infopublic/aboutUs.do?action=carryout");
		//window.location.href = getOrdinaryPath('/fecsp/surf/infopublic/infolist.do?action=carryout&infoType=AboutUs');
		window.location.href = 'http://www.tj.sgcc.cn';
	},
	setAsHomePage: function() {		
		if (Ext.isIE) {
			var body = Ext.getBody();
			body.setStyle('behavior', 'url(#default#homepage)');
			body.dom.setHomePage(window.location.href);
		}
	},
	addToBookmarks: function() {
		var url = window.location.href;
		var title = document.title;		
	    try { 
	        window.external.addFavorite(url, title); 
	    } catch (e) { 
	        try { 
	            window.sidebar.addPanel(title, url, ""); 
	        } catch (e) { 
	            Ext.Msg.alert('添加收藏', '请使用Ctrl+D添加收藏。');
	        } 
	    }
	},
	doRSS: function() {
		new Fecsp.surf.infopublic.RSSListWindow().show();
	},
	openDownloadCenter: function() {
		window.location.href = getOrdinaryPath('/fecsp/surf/infopublic/infolist.do?action=carryout&infoType=DownloadCenter');
	},
	go2OldHome: function() {
		window.location.href = getOrdinaryPath('/fecsp/surf/base/oldhome.do?action=carryout');
	},
	go2MblHome: function() {
		if(MOBILE_HOME==null || MOBILE_HOME == '/fecsp/surf/index.jsp' || MOBILE_HOME == 'null'){
			Ext.Msg.alert('提示','手机版暂不可用');
		}else {
			window.location.href = MOBILE_HOME;
		}
	},
	openFriendshipLink: function() {
		window.location.href = getOrdinaryPath('/fecsp/surf/infopublic/showFriendshipLink.do?action=carryout');
	},
	doSearch: function() {
		if (this.rendered) {
			var tKeywords = Ext.DomQuery.selectNode('input[name=keywords]', this.el.dom);
			var queryContent = encodeURIComponent(tKeywords.value);
			window.open(getOrdinaryPath('/fecsp/surf/retrieval/retrieval.do?action=init&queryContent=' + queryContent));
		}
	}	
});

Fecsp.surf.base.Home.Footer = Ext.extend(Ext.BoxComponent, {
	tpl: new Ext.Template(
		'<table cellspacing="0" cellpadding="0" border="0" style="width:100%; height:100%">',
		'	<tr>',
		'		<td class="footer">',
		'			您是 天津市电力公司95598网上营业厅 第 {0} 位访客<br/>',
		'			版权所有：天津市电力公司 推荐使用1024*768分辨率浏览本页面以获得最佳效果<br/>',
		'			津ICP备05003357号',		
		'		</td>',
		'	</tr>',
		'</table>',
		{
			compiled: true,
			disableFormats: true
		}
	),
	data: [0],
	afterRender: function() {
		Fecsp.surf.base.Home.Footer.superclass.afterRender.apply(this, arguments);
		Ext.Ajax.request({
			url: (CONTEXT_PATH + '/handleAJAXRequest'),
			params: {
				hcn: 'scipb.plat.webcommon.fbase.webapp.arhs.VisitPlaceGetter'
			},
			callback: function(options, success, response) {
				if (success) {
					var responseJSON = Ext.decode(response.responseText);
					if (responseJSON.success) {
						var data = [responseJSON.data.visitPlace];
						this.update(data);
					}
				}
			},
			scope: this
		});
	}
});

Ext.reg('home-header', Fecsp.surf.base.Home.Header);
Ext.reg('home-footer', Fecsp.surf.base.Home.Footer);
