/**
 * mainframe.js
 */
var baseUrl = '';
var theme = '';
var viewAlarmType,pieAlarmType,statusType;
Ext.Loader.setConfig({
    enabled: true
});

Ext.Loader.setPath('Ext.ux', '../../res/extjs/examples/ux');
Ext.require([
	  'Ext.panel.Panel',
	  'Ext.button.Button',
	  'Ext.window.Window',
	  'Ext.ux.statusbar.StatusBar',
	  'Ext.toolbar.TextItem',
	  'Ext.menu.Menu',
	  'Ext.toolbar.Spacer',
	  'Ext.button.Split',
	  'Ext.form.field.TextArea',
	  'Ext.util.TaskRunner'
	]);

var task = {   
	    run : function() { 
	    	Ext.getCmp('timestamp_bar').setValue(Ext.Date.format(new Date(), 'Y-m-d H:i:s'));
	    },   
	    interval : 1000   
	};


var setCompanyCode = function(id){
	$("#company_code").val(id);
}

var subAlarm = Ext.create('Ext.menu.Menu',{
	items:[
		{
			text : '火灾监控',
			cls:'usky_menu',
			iconCls : 'menu_fire_btn',
			disabled:($("#V_LOGINNAME").val()=='guest'),
			handler: function() {
				var div = document.getElementById('main_center_layout');
				try{
					div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/fireAlarm/subFireAlarm.jsp?theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
				}catch(e){}
			}
		},{
			text : '电气火灾监控',
			cls:'usky_menu',
			iconCls : 'menu_efire_btn',
			disabled:($("#V_LOGINNAME").val()=='guest'),
			handler: function() {
				var div = document.getElementById('main_center_layout');
				try{
					div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/efireAlarm/subeFireAlarm.jsp?theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
				}catch(e){}
			}
		},{
			text : '消防水系统监控',
			cls:'usky_menu',
			iconCls : 'menu_water_btn',
			disabled:($("#V_LOGINNAME").val()=='guest'),
			handler: function() {
				var div = document.getElementById('main_center_layout');
				try{
					div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/waterAlarm/subWaterAlarm.jsp?theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
				}catch(e){}
			}
		},{
			text : 'RTU综合监控',
			cls:'usky_menu',
			iconCls : 'menu_efire_btn',
			disabled:($("#V_LOGINNAME").val()=='guest'),
			handler: function() {
				var div = document.getElementById('main_center_layout');
				try{
					div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/rtuAlarm/subRtuAlarm.jsp?theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
				}catch(e){}
			}
		}
	]
});

var subDevice = Ext.create('Ext.menu.Menu',{
	items:[
		{
			text : '火灾监控',
			cls:'usky_menu',
			iconCls : 'menu_fire_btn',
			disabled:($("#V_LOGINNAME").val()=='guest'),
			handler: function() {
				var div = document.getElementById('main_center_layout');
				try{
					div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/fireAlarm/FireDeviceIndex.jsp?theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
				}catch(e){}
			}
		},{
			text : '电气火灾监控',
			cls:'usky_menu',
			iconCls : 'menu_efire_btn',
			disabled:($("#V_LOGINNAME").val()=='guest'),
			handler: function() {
				var div = document.getElementById('main_center_layout');
				try{
					div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/efireAlarm/eFireDeviceIndex.jsp?theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
				}catch(e){}
			}
		},{
			text : '消防水系统监控',
			cls:'usky_menu',
			iconCls : 'menu_water_btn',
			disabled:($("#V_LOGINNAME").val()=='guest'),
			handler: function() {
				var div = document.getElementById('main_center_layout');
				try{
					div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/waterAlarm/WaterDeviceIndex.jsp?theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
				}catch(e){}
			}
		},{
			text : 'RTU综合监控',
			cls:'usky_menu',
			iconCls : 'menu_efire_btn',
			disabled:($("#V_LOGINNAME").val()=='guest'),
			handler: function() {
				var div = document.getElementById('main_center_layout');
				try{
					div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/rtuAlarm/RtuDeviceIndex.jsp?theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
				}catch(e){}
			}
		}
	]
});

var subData = Ext.create('Ext.menu.Menu',{
	items:[
		{
			text : '电气火灾数据查询',
			cls:'usky_menu',
			iconCls : 'menu_fire_btn',
			disabled:($("#V_LOGINNAME").val()=='guest'),
			handler: function() {
				var div = document.getElementById('main_center_layout');
				try{
					div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/dataSearch/fireIndex.jsp?theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
				}catch(e){}
			}
		},{
			text : '消防水系统数据查询',
			cls:'usky_menu',
			iconCls : 'menu_water_btn',
			disabled:($("#V_LOGINNAME").val()=='guest'),
			handler: function(){
				var div = document.getElementById('main_center_layout');
				try{
					div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/dataSearch/index.jsp?theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
				}catch(e){}
			}
//			handler: function() {
//				var div = document.getElementById('main_center_layout');
//				try{
//					div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/waterAlarm/WaterDeviceIndex.jsp?theme='+theme+'"></iframe>';
//				}catch(e){}
//			}
		},{
			text : 'RTU综合数据查询',
			cls:'usky_menu',
			iconCls : 'menu_efire_btn',
			disabled:($("#V_LOGINNAME").val()=='guest'),
			handler: function() {
				var div = document.getElementById('main_center_layout');
				try{
					div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/dataSearch/rtuIndex.jsp?theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
				}catch(e){}
			}
		}
	]
});

var routData = Ext.create('Ext.menu.Menu',{
	items:[
		{
			text : '巡检计划',
			cls:'usky_menu',
			iconCls : 'menu_fire_btn',
			handler: function() {
				var div = document.getElementById('main_center_layout');
				try{
					div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/patrolplan/index.jsp?theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
				}catch(e){}
			}
		},{
			text : '巡检点位',
			cls:'usky_menu',
			iconCls : 'menu_fire_btn',
			handler: function() {
				var div = document.getElementById('main_center_layout');
				try{
					div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/patrolpoint/index.jsp?theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
				}catch(e){}
			}
		},{
			text : '巡检路线',
			cls:'usky_menu',
			iconCls : 'menu_fire_btn',
			handler: function() {
				var div = document.getElementById('main_center_layout');
				try{
					div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/route/index.jsp?theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
				}catch(e){}
			}
		},{
			text : '巡检记录',
			cls:'usky_menu',
			iconCls : 'menu_fire_btn',
			handler: function() {
				var div = document.getElementById('main_center_layout');
				try{
					div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/checkrecord/index.jsp?theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
				}catch(e){}
			}
		},{
			text : '巡检点操作记录',
			cls:'usky_menu',
			iconCls : 'menu_fire_btn',
			handler: function() {
				var div = document.getElementById('main_center_layout');
				try{
					div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/inspectionrecord/index.jsp?theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
				}catch(e){}
			}
		}
	]
});

var menuMain = Ext.create('Ext.menu.Menu',{
	items: [{
		text : '综合查询',
		cls:'usky_menu',
		iconCls : 'menu_frontpage_btn',
		handler: function(){
			var div = document.getElementById('main_center_layout');
			var type = $("#viewAlarmType").val();
			try{
				div.innerHTML='<iframe id="frame_frontpage" frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/frontpage/map.jsp?viewAlarmType='+viewAlarmType+'&pieAlarmType='+pieAlarmType+'&statusType='+statusType+'&theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
			}catch(e){}
		}
	},{
		text : '告警信息',
		cls:'usky_menu',
		iconCls : 'menu_alarm_btn',
		menu: subAlarm
	},{
		text : '设备监控',
		cls:'usky_menu',
		iconCls : 'menu_device_btn',
		menu: subDevice
	},{
		text : '数据查询',
		cls:'usky_menu',
//		disabled:true,
		iconCls : 'menu_data_btn',
		menu: subData
	},{
		text : '巡检工作',
		cls:'usky_menu',
//		disabled:true,
		iconCls : 'menu_around_btn',
		disabled:($("#V_LOGINNAME").val()=='guest'),
		menu: routData
	},{
		text : '工作考评',
		cls:'usky_menu',
		disabled:true,
		iconCls : 'menu_work_btn'
	}]
});

var menuSub = Ext.create('Ext.menu.Menu',{
	items: [{
		text : '火灾监控',
		cls:'usky_menu',
		iconCls : 'menu_fire_btn',
		disabled:($("#V_LOGINNAME").val()=='guest'),
		handler: function() {
			var div = document.getElementById('main_center_layout');
			try{
				div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/fireAlarm/index.jsp?theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
			}catch(e){}
		}
	},{
		text : '电器火灾监控',
		cls:'usky_menu',
		iconCls : 'menu_efire_btn',
		disabled:($("#V_LOGINNAME").val()=='guest'),
		disabled: true
	},{
		text : '消防水系统监控',
		cls:'usky_menu',
		iconCls : 'menu_water_btn',
		disabled:($("#V_LOGINNAME").val()=='guest'),
		handler: function() {
			var div = document.getElementById('main_center_layout');
			try{
				div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/waterAlarm/index.jsp?theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
			}catch(e){}
		}
	},{
		text : '通道告警监控',
		cls:'usky_menu',
		iconCls : 'menu_access_btn',
		disabled: true
	},{
		text : '消防电源监控',
		cls:'usky_menu',
		iconCls : 'menu_power_btn',
		disabled: true
	},{
		text : 'RTU综合监控',
		cls:'usky_menu',
		iconCls : 'menu_efire_btn',
		disabled:($("#V_LOGINNAME").val()=='guest'),
		handler: function() {
			var div = document.getElementById('main_center_layout');
			try{
				div.innerHTML='<iframe frameborder=0 width="100%" height="100%" allowtransparency="true" scrolling=auto src="'+baseUrl+'view/rtuAlarm/index.jsp?theme='+theme+($("#company_code").val().length>0?('&company_code='+$("#company_code").val()):'')+'"></iframe>';
			}catch(e){}
		}
	}]
});

var chkViewMapAlarm = function(id){
	var str = "";
	var len=8;
	var check = new Array();
	for(var i=0;i<len;i++){
		check.push(Ext.getCmp('viewMapAlarm'+i));
	}
	if(id==0){
		if(check[0].checked==true){
			for(var i=1;i<len;i++){
				if(!check[i].isDisabled()){
					check[i].setChecked(true);
				}
			}
		}else{
			for(var i=1;i<len;i++){
				check[i].setChecked(false);
			}
		}
	}
	for(var i=0;i<len;i++){
		if(check[i].checked==true){
			str +="1";
		}else{
			str +="0";
		}
	}
	$("#viewAlarmType").val(str);
	try{
		document.getElementById("frame_frontpage").contentWindow.changeMapView(str);
	}catch(e){}
}

var viewMap = Ext.create('Ext.menu.Menu',{
	items : [{
		xtype: 'menucheckitem',
		id: 'viewMapAlarm0',
		text: '全选',
		cls:'usky_menu',
		checked: 'checked',
		handler :function(){
			chkViewMapAlarm(0);
		}
	},{
		xtype: 'menucheckitem',
		id: 'viewMapAlarm1',
		text: '火警监控系统告警',
		cls:'usky_menu',
		checked: 'checked',
		handler : function(){
			chkViewMapAlarm(1);
		}
	},{
		xtype: 'menucheckitem',
		id: 'viewMapAlarm2',
		text: '电气火灾监控系统告警',
		cls:'usky_menu',
		checked: 'checked',
//		disabled: true,
		handler : function(){
			chkViewMapAlarm(2);
		}
	},{
		xtype: 'menucheckitem',
		id: 'viewMapAlarm3',
		text: '消防水监控系统告警',
		cls:'usky_menu',
		checked: 'checked',
		handler : function(){
			chkViewMapAlarm(3);
		}
	},{
		xtype: 'menucheckitem',
		id: 'viewMapAlarm4',
		text: '通道监控系统告警',
		cls:'usky_menu',
		disabled: true,
		handler : function(){
			chkViewMapAlarm(4);
		}
	},{
		xtype: 'menucheckitem',
		id: 'viewMapAlarm5',
		text: '消防电源监控系统告警',
		cls:'usky_menu',
		disabled: true,
		handler : function(){
			chkViewMapAlarm(5);
		}
	},{
		xtype: 'menucheckitem',
		text: 'RTU监控系统告警',
		cls:'usky_menu',
		id: 'viewMapAlarm6',
		checked: 'checked',
		handler : function(){
			chkViewMapAlarm(6);
		}
	},{
		xtype: 'menucheckitem',
		text: '烟感监控系统告警',
		cls:'usky_menu',
		id: 'viewMapAlarm7',
		
		disabled: true,
		handler : function(){
			chkViewMapAlarm(7);
		}
	}]
});

var viewTheme = Ext.create('Ext.menu.Menu',{items : [{id: 'view_theme_default',xtype: 'menucheckitem',group: 'theme',text: '经典',cls:'usky_menu',handler : function(){location.href = baseUrl + 'view/mainframe.jsp?theme=default';}},{id: 'view_theme_gray',xtype: 'menucheckitem',group: 'theme',text: '灰色',cls:'usky_menu',handler : function(){location.href = baseUrl + 'view/mainframe.jsp?theme=gray';}},{id: 'view_theme_access',xtype: 'menucheckitem',group: 'theme',text: '反白',cls:'usky_menu',handler : function(){location.href = baseUrl + 'view/mainframe.jsp';}}]});
var alarmScope = Ext.create('Ext.menu.Menu',{
	items : [
		new Ext.menu.CheckItem({
