var g_event_tab_styles = null;
var COL_EVENT_SELECT = 0;
var COL_EVENT_NO = 1;
var COL_EVENT_TYPE = 2;
var COL_EVENT_CARD = 3;
var COL_EVENT_EMP_NAME = 4;
var COL_EVENT_EMP_CODE = 5;
var COL_EVENT_TIME = 6;
var COL_EVENT_DEVICE_NAME = 7;
var COL_EVENT_READER = 9;
var COL_EVENT_TEMPETATURE = 8;
var g_event_tab_index = new Array(COL_EVENT_SELECT,COL_EVENT_NO,COL_EVENT_TYPE,COL_EVENT_EMP_NAME,COL_EVENT_CARD,COL_EVENT_EMP_CODE,COL_EVENT_DEVICE_NAME,COL_EVENT_READER,COL_EVENT_TIME);
var g_event_tab_data_styles = [
					{"index":COL_EVENT_SELECT,"name":getCheckBoxById(1000,'cb_all_event_','callBackAllSelectedEvent'),"isDisplay":0,"align":"center","width":40,"noWrap":"nowrap","addBtnMode":VAR_MODE_UIOBJ,"padding":-1,"isSort":false,"cutStrLen":50,setMode:UI_MODE_CHECKBOX,"fwidth":0,"key":"szNumber","default":""},
					{"index":COL_EVENT_NO,"name":getLanTextByKey("T_SN"),"isDisplay":1,"align":"center","width":40,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":50,"fwidth":34,"key":"szNumber","default":""},
					{"index":COL_EVENT_TYPE,"name":getLanTextByKey("T_EVENT_TYPE_TITLE"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":50,"fwidth":64,"key":"szType","default":""},
					{"index":COL_EVENT_CARD,"name":getLanTextByKey("T_CARD_NUMBER"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":50,"fwidth":80,"key":"szCard","default":""},
					{"index":COL_EVENT_EMP_NAME,"name":getLanTextByKey("T_STAFF_MANAGEMENT"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":50,"fwidth":80,"key":"szName","default":""},
					{"index":COL_EVENT_EMP_CODE,"name":getLanTextByKey("T_CODE"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":40,"fwidth":50,"key":"szCode","default":""},
					{"index":COL_EVENT_TIME,"name":getLanTextByKey("T_TIME_TITLE"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":50,"fwidth":80,"key":"szTime","default":""},
					{"index":COL_EVENT_DEVICE_NAME,"name":getLanTextByKey("ADD_CONTROLLER_DEVICE_LIST_DESC"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":50,"fwidth":80,"key":"szDev","default":""},
					{"index":COL_EVENT_READER,"name":getLanTextByKey("T_READER_TITLE"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":50,"fwidth":42,"key":"szReader","default":""}
					];
if(g_temperatureFuncObj["open"])
{
  g_event_tab_data_styles.push({"index":COL_EVENT_TEMPETATURE,"name":getLanTextByKey("T_TEMPERATURE_NAME"),"isDisplay":1,"align":"center","width":40,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":50,"fwidth":70,"key":"nTemperature","default":""});
  g_event_tab_index.splice(g_event_tab_index.length - 1,0,COL_EVENT_TEMPETATURE);
}
var g_aEventItems = null;
var g_szEventName = "";
var g_szEventCode = "";
var g_nEventType = "-1";
var g_nEventDepartmentID = "-1";
var g_nEventDevice = "-1";
var g_szEventStart = "";
var g_szEventEnd = "";

var g_alarm_tab_styles = null;
var g_nAlarmType = "-1";
var g_nAlarmDevice = "-1";
var g_szAlarmStart = "";
var g_szAlarmEnd = "";
var COL_ALARM_SELECT = 0;
var COL_ALARM_NO = 1;
var COL_ALARM_TYPE = 2;
var COL_ALARM_DEVICE_NAME = 3;
var COL_ALARM_POSITION = 4;
var COL_ALARM_TIME = 5;
var g_alarm_tab_index = new Array(COL_ALARM_SELECT,COL_ALARM_NO,COL_ALARM_TYPE,COL_ALARM_DEVICE_NAME,COL_ALARM_POSITION,COL_ALARM_TIME);
var g_alarm_tab_data_styles = [
					{"index":COL_ALARM_SELECT,"name":getCheckBoxById(1000,'cb_all_alarm_','callBackAllSelectedAlarm'),"isDisplay":0,"align":"center","width":40,"noWrap":"nowrap","addBtnMode":VAR_MODE_UIOBJ,"padding":-1,"isSort":false,"cutStrLen":50,setMode:UI_MODE_CHECKBOX,"fwidth":0,"key":"szReader","default":""},
					{"index":COL_ALARM_NO,"name":getLanTextByKey("T_SN"),"isDisplay":1,"align":"center","width":40,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":50,"fwidth":50,"key":"szReader","default":""},
					{"index":COL_ALARM_TYPE,"name":getLanTextByKey("T_ALARM_TYPE_TITLE"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":50,"fwidth":50,"key":"szType","default":""},	
					{"index":COL_ALARM_DEVICE_NAME,"name":getLanTextByKey("ADD_CONTROLLER_DEVICE_LIST_DESC"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":50,"fwidth":100,"key":"szDev","default":""},	
					{"index":COL_ALARM_POSITION,"name":getLanTextByKey("T_ALARM_POSTITION_TITLE"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":50,"fwidth":50,"key":"szPosition","default":""},		
					{"index":COL_ALARM_TIME,"name":getLanTextByKey("T_TIME_TITLE"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":50,"fwidth":80,"key":"szTime","default":""}
					];
function resetEventQueryGlobalonditions()
{
	g_szEventName = "";
	g_szEventCode = "";
	g_nEventType = "-1";
	g_nEventDepartmentID = "-1";
	g_nEventDevice = "-1";
	g_szEventStart = "";
	g_szEventEnd = "";
}
//查询事件记录
function getEventItemsByPageIndex(nPage)
{
	ListEventItems(g_nEventType,g_nEventDepartmentID,g_nEventDevice,g_szEventCode,g_szEventName,g_szEventStart,g_szEventEnd,g_pageSize,nPage,true);
}
//查询事件记录
function ListEventItems(nType,nDepartmentID,nDevice,szCode,szName,szStart,szEnd,pageSize,nPage,bAscOrderTime,callBackMethod)
{
	g_aEventItems = new Array();
	g_sn = 0;
	console.log("pageSize="+pageSize+",nPage="+nPage+",nType = "+nType+", nDepartmentID="+nDepartmentID+",nDevice="+nDevice+",szName="+szName+",szCode="+szCode+",szStart="+szStart+",szEnd="+szEnd);
	startProcess(1,null);
	OnEventItem.callBackMethod = null;
	if(callBackMethod != undefined)
		OnEventItem.callBackMethod = callBackMethod;
	var ret = _externalListEvent('OnEventItem', pageSize, nPage, 
																 /*事件类型。为-1时表示所有类型。其它类型码如下：
																	#define AS_ME_EVENT_TYPE_LEGAL_CARD         0    //合法卡,注释码2
																	#define AS_ME_EVENT_TYPE_ILLEGAL_CARD       1    //非法卡,注释码1
																	#define AS_ME_EVENT_TYPE_LEGAL_PASSWORD     2    //密码开门,注释码3
																	#define AS_ME_EVENT_TYPE_ILLEGAL_PASSWORD   3    //非法密码,注释码4
																	#define AS_ME_EVENT_TYPE_SWITCH             4    //出门按钮,注释码5
																	#define AS_ME_EVENT_TYPE_URGENCY_CODE       5    //胁迫码,注释码6
																	#define AS_ME_EVENT_TYPE_PREVENT_BACK       6    //卡被防潜回,注释码0
																	#define AS_ME_EVENT_TYPE_ARM                9    //撤布防,注释码9,注释码10
																	#define AS_ME_EVENT_TYPE_LEGAL_FP           11   //合法指纹
																	#define AS_ME_EVENT_TYPE_ILLEGAL_FP         12   //非法指纹*/
																nType,
																nDepartmentID/*部门ID。为-1时表示任何部门*/, 
																nDevice/*设备或门ID。为-1时表示任何设备*/, 
																szName/*模糊查询人员名称。为空字符串表示任何人员。*/, 
																szCode/*模糊查询人员编号。为空字符串表示任何编码。*/, 
																szStart/*起始时间字串。结束时间必须晚于该时间。格式为 "YYYY-MM-DD HH:mm:ss"*/, 
																szEnd/*结束时间字串*/, 
																bAscOrderTime/*时间排序*/);
	
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作
		return 0;
	}
	showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);
	cancelProcess();
}
//回调函数，每得到一条设备信息被调用一次
var EXIT_BTN_EVENT_TYPE = 4;//出门按钮事件
var FACE_EVENT_TYPE = 13;//合法人脸事件
var TEMPERATURE_UNNORMAL_TYPE = 15;//温度异常事件
function OnEventItem(szItem)
{
	eval('var item = ' + szItem);
	/*
	回调格式：基本上与listEmplyee相似,仅获取的每条数据内容不同，格式如下：
	{nCode:0,szType:"%s",szCard:"%s",szName:"%s",szCode:"%s",szDev:"%s",")
									_T("szDoor:"%s",szReader:"%s",szTime:"%s"}
	
	szType:事件类型
	szCard:卡号（如果有，否则为空字符串）
	szName:人员姓名（如果有，否则为空字符串）
	szCode:人员编号（如果有，否则为空字符串）
	szDev:设备名
	szDoor:门名（如果有，否则为空字符串）
	szReader：读头名（如果有，否则为空字符串）
	szTime:事件产生时间字串，格式为"YYYY-MM-DD HH:mm:ss"
  nTemperature温度
	*/

	if (item.nCode == 1)//列表线程已启动
	{
		//此时item结构如下
		//item.nCode 肯定为1
		//item.nPage 当前页页号
		//item.nRows 每页最大显示行数
		//item.nTotalPages 搜索结果总页数	
		if(g_nTotalPage != item.nTotalPages && g_nTotalPage)
			g_isInitSplitPage = false;		
		if(g_nPage != item.nPage)
			g_isInitSplitPage = false;	
		g_nPage = item.nPage;
		g_nTotalPage = item.nTotalPages;
    //console.log("得到总页数 g_nTotalPage = "+g_nTotalPage);
		if(g_isInitListUI)
		{
			if(!g_isInitSplitPage)
			{
				g_isInitSplitPage = true;
				initSplitPageTable(document.getElementById("td_tab_list_split"),g_nTotalPage,g_nPage,"getEventItemsByPageIndex",g_currentTabListId);	
			}
		}		
		return;
	}
	else if (item.nCode == 2)
	{
    if(OnEventItem.methodParams != undefined && OnEventItem.methodParams != null)
    {
      //console.log("g_nTotalPage = " + g_nTotalPage + ", currentPageIndex = " +(OnEventItem.methodParams)["PageIndex"] +",res = " + (g_nTotalPage === (OnEventItem.methodParams)["PageIndex"]));
      if(g_nTotalPage <= (OnEventItem.methodParams)["PageIndex"])
        cancelProcess();
      else
      {
        (OnEventItem.methodParams)["PageIndex"]++;       
        //console.log("查询第：" +(OnEventItem.methodParams)["PageIndex"]+ "页");
        ListEventItems((OnEventItem.methodParams)["EventType"],(OnEventItem.methodParams)["EventDepartmentID"],(OnEventItem.methodParams)["EventDevice"],(OnEventItem.methodParams)["EventCode"],(OnEventItem.methodParams)["EventName"],(OnEventItem.methodParams)["EventStart"],(OnEventItem.methodParams)["EventEnd"],(OnEventItem.methodParams)["PageSize"],(OnEventItem.methodParams)["PageIndex"],(OnEventItem.methodParams)["bAscOrderTime"],(OnEventItem.methodParams)["CallBackMethod"]);
        return;
      }
    }
    else
		{
      cancelProcess();
      OnEventItem.methodParams = null;
    } 
		if(g_isInitListUI)
		{			
			initEventListItems(g_aEventItems);	
		}
		if(checkIsFuncList())
			callTailOfFuncList();
		if(OnEventItem.callBackMethod != null)	
			setTimeout(function(){OnEventItem.callBackMethod(g_aEventItems);},50);
		setTimeout(function(){g_aEventItems = null;},55);
		return;
	}
	else if (item.nCode < 0)
		showToast(item.szMsg,DIALOG_MASK_TIP_MODE,2);//同时也表示操作错误完成
	else if (item.nCode == 0)
	{
		var obj = getEventItemObj(++g_sn,item);
    if(obj != null){
		g_aEventItems.push(obj);
	}		  
    else
      console.log(szItem);
		if(OnEventItem.itemCallBackMethod != undefined && OnEventItem.itemCallBackMethod != null)
		{//console.log(OnEventItem.itemCallBackMethod);
			OnEventItem.itemCallBackMethod(OnEventItem.szPathFile,obj,g_event_tab_data_styles,g_event_tab_index);
		}
		return;
	}
	//else
//		alert("不应该到达此处，说明VC源代码有错误。");
	cancelProcess();
}
function getEventItemObj(sn,item)
{
  var bgColor = "";
  var color = "";
  if(item.nType === EXIT_BTN_EVENT_TYPE)//EXIT_BTN_EVENT_TYPE为出门按钮
  {
    item.szCard = "";
    item.nTemperature = "";
  } 
  else if(item.nType === FACE_EVENT_TYPE)
    item.nTemperature = (item.nTemperature != undefined && item.nTemperature != -1)?getTemperatureStrByMode(item.nTemperature):"";
  else if(item.nType === TEMPERATURE_UNNORMAL_TYPE)//温度异常事件
  {//console.log("************");console.log(item);console.log(item.szName + ")item.nType: "+item.nType+", item.nTmprType =" +item.nTmprType);
    item.nTemperature = (item.nTemperature != undefined && item.nTemperature != -1)?getTemperatureStrByMode(item.nTemperature):"";
    if(item.nTmprType === 2)
      bgColor = getLanTextByKey("C_WEB_TEMPERATUER_HIGH_REC_BKCOLOR");   
    else if(item.nTmprType === 1)
      bgColor = getLanTextByKey("C_WEB_TEMPERATUER_LOW_REC_BKCOLOR");   
    color = getLanTextByKey("C_WEB_TEMPERATUER_UNNORMAL_REC_FCOLOR");  
   console.log("bgColor = "+bgColor+",color="+color);
  }
  else
    item.nTemperature = "";
	console.log("szCard = " + item.szCard);
	if(item.szCard === "" | item.szCard === 0)
		item.szCard = "";
	var cbObj = getCheckBoxById(sn,"cb_event_","selectedEmpCallBack",g_checkBoxNormalBorderColor);
	var jsons = [{"index":COL_EVENT_SELECT,"val":cbObj},{"index":COL_EVENT_NO,"val":sn + g_pageSize * (g_nPage-1)},{"index":COL_EVENT_TYPE,"val":item.szType},{"index":COL_EVENT_CARD,"val":item.szCard},{"index":COL_EVENT_EMP_NAME,"val":item.szName},{"index":COL_EVENT_EMP_CODE,"val":item.szCode},{"index":COL_EVENT_TIME,"val":item.szTime},{"index":COL_EVENT_DEVICE_NAME,"val":item.szDev},{"index":COL_EVENT_READER,"val":item.szReader},{"index":COL_EVENT_TEMPETATURE,"val":item.nTemperature},{"condition":0,"trBkColor":bgColor,"trColor":color,"tips":"",obj:item,callbackmethod:""}];	//rowHoverCallBackEvent
	return jsons;
}
function getTemperatureStrByMode(num)
{
  var nTstr = "";
  for(var i = 0; i < g_temperatureFuncObj["dmode"].length; i++)
  {
    nTstr += ((i != 0)?"/":"") + getTemperatureByMode(num,g_temperatureFuncObj["dmode"].charAt(i));
  }
  return nTstr;
}
function getTemperatureByMode(num,mode)
{
  switch(mode)
  {
    case "1":
      return (num / 100).toFixed(g_temperatureFuncObj["precision"]) + "℃";
    case "2":
      return (num / 100 * 5 / 9 + 32).toFixed(g_temperatureFuncObj["precision"]) + "℉";
  }
}
function exportReords(aItems,aStyles,aIndex)
{
	var szFilter = "Excel Files(*.xlsx)|*.xlsx|";
	var szTitle = getLanTextByKey("T_EXPORT_EMP_SELECT_FILE_TIPS");
	//获取导出文件全路径名
	var szPathFile = _externalSelectFile(szFilter, szTitle, true);
	//console.log("szPathFile="+szPathFile);
	if(szPathFile == null)
		return;
	
	var headerStr = "";
	var count = 0;
	aStyles = sortByaKeyVal(aStyles,aIndex,"index",true);
	for(var j = 0; j < aStyles.length; j++)
	{
		if(aStyles[j]["isDisplay"])
		{//console.log(j+")"+aStyles[j]["name"]);			
			headerStr += ((count == 0)?'"':',"') + aStyles[j]["name"] + '"';
			count++;
		}
	}
	var nCols = count;
	//console.log("nCols = "+nCols);
	var nRes = _externalExlBeginExport(szPathFile, nCols);
	//console.log("创建文件："+nRes);
	//console.log('nRes = _externalExlExportRow(' + headerStr + ');');
	eval('nRes = _externalExlExportRow(' + headerStr + ');');
	if(!nRes)
	{
		nRes = _externalExlEndExport();
		return;
	}
	var rowStr = "";
  
	for(var i = 0; i < aItems.length; i++)
	{
		count = 0;
		rowStr = "";
		
		//if(i == 0)console.log(aItems[i]);
		var item = aItems[i][aItems[i].length - 1]["obj"];
		//console.log(item);
		for(var j = 0; j < aItems[i].length; j++)
		{
			if(aItems[i][j]["index"] == COL_DEPT)
				item.nDepartment = aItems[i][j]["val"];
			else if(aItems[i][j]["index"] == COL_GENDER)			
				item.dwGender = aItems[i][j]["val"];
			else if(aItems[i][j]["index"] == COL_GROUP)
				item.dwFlag = aItems[i][j]["val"];
		}
		for(var j = 0; j < aStyles.length; j++)
		{
			if(j == 0)
			{
				rowStr += '"'+(i + 1) + '"';
				count++;
			}	
			else if(item[aStyles[j]["key"]] != undefined)
			{
				rowStr += ((count == 0)?'"':',"') + item[aStyles[j]["key"]] + '"';
				count++;
			}
		}
		eval('nRes = _externalExlExportRow(' + rowStr + ');');
		if(!nRes)
		{
			nRes = _externalExlEndExport();
			return;
		}
	}
//	console.log("插入数据："+nRes);
	nRes = _externalExlEndExport();
//	console.log("导入结束："+nRes);
	setTimeout(function(){g_startProc = true;cancelProcess(null,4);},100);
}
var g_countExportItems = -1;
function initExlsFile(aStyles,aIndex)
{
	var headerStr = "";
	var count = 0;
	var szFilter = "Excel Files(*.xlsx)|*.xlsx|";
	var szTitle = getLanTextByKey("T_EXPORT_EMP_SELECT_FILE_TIPS");
	aStyles = sortByaKeyVal(aStyles,aIndex,"index",true);
	for(var j = 0; j < aStyles.length; j++)
	{
		if(aStyles[j]["isDisplay"])
		{//console.log(j+")"+aStyles[j]["name"]);			
			headerStr += ((count == 0)?'"':',"') + aStyles[j]["name"] + '"';
			count++;
		}
	}
	
	//获取导出文件全路径名
	var szPathFile = _externalSelectFile(szFilter, szTitle, true);
  if(szPathFile == null)
    return null;
	var nCols = count;
	//console.log("nCols = "+nCols);
	var nRes = _externalExlBeginExport(szPathFile, nCols);
	if(!nRes)
	{
		nRes = _externalExlEndExport();
		return;
	}
	//console.log("创建文件："+nRes);
	//console.log('nRes = _externalExlExportRow(' + headerStr + ');');
	
	eval('nRes = _externalExlExportRow(' + headerStr + ');');
	g_countExportItems = 1;
	return szPathFile;
}
function endExportRecordItem()
{
	var nRes = _externalExlEndExport();
	setTimeout(function(){
		g_startProc = true;
		cancelProcess(null,4);
		g_countExportItems = -1;
		},100);	
}
function exportReordItem(szPathFile,item,aStyles,aIndex)
{
  aStyles = sortByaKeyVal(aStyles,aIndex,"index",true);
	
	var count = 0;
	
	var rowStr = "";
	var item = item[item.length - 1]["obj"];		
	for(var j = 0; j < aStyles.length; j++)
	{
		if(j == 0)
		{
			rowStr += '"'+(g_countExportItems++) + '"';
			count++;
		}	
		else if(item[aStyles[j]["key"]] != undefined)
		{
			rowStr += ((count == 0)?'"':',"') + item[aStyles[j]["key"]] + '"';
			count++;
		}
	}
	eval('nRes = _externalExlExportRow(' + rowStr + ');');
}
///////////////////报警记录查询  开始//////////////////////////////////
function resetAlarmQueryGlobalonditions()
{
	g_nAlarmType = "-1";
	g_nAlarmDevice = "-1";
	g_szAlarmStart = "";
	g_szAlarmEnd = "";
}
//查询报警记录
function getAlarmItemsByPageIndex(nPage)
{
	ListAlarmItems(g_nAlarmType,g_nAlarmDevice,g_szAlarmStart,g_szAlarmEnd,g_pageSize,nPage,true);
}
//查询报警记录
var g_aAlarmItems = null;
function ListAlarmItems(nType,nDevice,szStart,szEnd,pageSize,nPage,bAscOrderTime,callBackMethod)
{
	g_aAlarmItems = new Array();
	g_sn = 0;
	console.log("pageSize="+pageSize+",nPage="+nPage+",nType = "+nType+",nDevice="+nDevice+",szStart="+szStart+",szEnd="+szEnd);
	startProcess(1,null);
	OnAlarmItem.callBackMethod = null;
	if(callBackMethod != undefined)
		OnAlarmItem.callBackMethod = callBackMethod;
	var ret = _externalListAlarm('OnAlarmItem', pageSize, nPage, 
																 /*nType:报警类型。为-1时表示所有类型。其它类型码如下：
																	#define AS_ME_ALARM_TYPE_WING_TIMEOUT   0     //门开超时报警，注释码1
																	#define AS_ME_ALARM_TYPE_ALARM_INPUT    1     //报警输入，注释码4
																	#define AS_ME_ALARM_TYPE_BREAK_INTO     2     //破门而入（隐含门磁输入有信号不再重复发送），注释码3
																	#define AS_ME_ALARM_TYPE_ALARM_INPUT_EX 3     //扩展板报警输入，注释码5
																	#define AS_ME_ALARM_TYPE_TAMPER         4     //一体机被拆除*/
																nType,
																nDevice/*设备或门ID。为-1时表示任何设备*/, 
																szStart/*起始时间字串。结束时间必须晚于该时间。格式为 "YYYY-MM-DD HH:mm:ss"*/, 
																szEnd/*结束时间字串*/, 
																bAscOrderTime/*时间排序*/);
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作
		return 0;
	}
	showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);
	cancelProcess();
}
//回调函数，每得到一条设备信息被调用一次
function OnAlarmItem(szItem)
{
	eval('var item = ' + szItem);
	/*
	{nCode:0,szType:"%s",szDev:"%s",")
                _T("szPosition:"%s",szTime:"%s"}
	szType:报警类型
	szDev:设备名
	szPosition:门名、报警端子或扩展报警端子名（如果有，否则为空字符串）
	szTime:报警产生时间字串，格式为"YYYY-MM-DD HH:mm:ss"
	*/
	if (item.nCode == 1)//列表线程已启动
	{
		//此时item结构如下
		//item.nCode 肯定为1
		//item.nPage 当前页页号
		//item.nRows 每页最大显示行数
		//item.nTotalPages 搜索结果总页数	
		if(g_nTotalPage != item.nTotalPages && g_nTotalPage)
			g_isInitSplitPage = false;		
		if(g_nPage != item.nPage)
			g_isInitSplitPage = false;	
		g_nPage = item.nPage;
		g_nTotalPage = item.nTotalPages;
		
		if(!g_isInitSplitPage)
		{
			g_isInitSplitPage = true;
			initSplitPageTable(document.getElementById("td_tab_list_split"),g_nTotalPage,g_nPage,"getAlarmItemsByPageIndex",g_currentTabListId);	
			//initSplitPageNavBySize(g_nTotalPage,g_nPage,"getEmpsByPageIndex");
			
		}
		return;
	}
	else if (item.nCode == 2)
	{		
    if(OnAlarmItem.methodParams != undefined && (OnAlarmItem.methodParams) != null)
    {
      if(g_nTotalPage === (OnAlarmItem.methodParams)["PageIndex"])
        cancelProcess();
      else
      {//ListAlarmItems(nType,nDevice,szStart,szEnd,pageSize,nPage,bAscOrderTime,callBackMethod)
        (OnAlarmItem.methodParams)["PageIndex"]++;        
        ListAlarmItems((OnAlarmItem.methodParams)["AlarmType"],(OnAlarmItem.methodParams)["AlarmDevice"],(OnAlarmItem.methodParams)["AlarmStart"],(OnAlarmItem.methodParams)["AlarmEnd"],(OnAlarmItem.methodParams)["PageSize"],(OnAlarmItem.methodParams)["PageIndex"],(OnAlarmItem.methodParams)["bAscOrderTime"],(OnAlarmItem.methodParams)["CallBackMethod"]);
        return;
      }
    }
    else
    {
      (OnAlarmItem.methodParams) = null;
      cancelProcess();
    }
		  
		if(g_isInitListUI)
			initAlarmListItems(g_aAlarmItems);
		if(OnAlarmItem.callBackMethod != null)
			setTimeout(function(){OnAlarmItem.callBackMethod(g_aAlarmItems);},200);
		setTimeout(function(){g_aAlarmItems = null;},250);
		return;
	}
	else if (item.nCode < 0)
		showToast(item.szMsg,DIALOG_MASK_TIP_MODE,2);//同时也表示操作错误完成
	else if (item.nCode == 0)
	{
		var obj = getAlarmItemObj(++g_sn,item);
		g_aAlarmItems.push(obj);
		console.log("*******************");
		if(OnAlarmItem.itemCallBackMethod != undefined && OnAlarmItem.itemCallBackMethod != null)
		{console.log("----------------------");
			OnAlarmItem.itemCallBackMethod(OnAlarmItem.szPathFile,obj,g_alarm_tab_data_styles,g_alarm_tab_index);
			console.log(item);
		}
		return;
	}
	//else
//		alert("不应该到达此处，说明VC源代码有错误。");
	cancelProcess();
}
function getAlarmItemObj(sn,item)
{
	var cbObj = getCheckBoxById(sn,"cb_Alarm_","selectedEmpCallBack",g_checkBoxNormalBorderColor);
	//console.log("**************************");
	//console.log(JSON.stringify(item));
	var jsons = [{"index":COL_ALARM_SELECT,"val":cbObj},{"index":COL_ALARM_NO,"val":sn + g_pageSize * (g_nPage-1)},{"index":COL_ALARM_TYPE,"val":item.szType},{"index":COL_ALARM_DEVICE_NAME,"val":item.szDev},{"index":COL_ALARM_POSITION,"val":getPosName(item)},{"index":COL_ALARM_TIME,"val":item.szTime},{"condition":0,"trBkColor":"","tips":"",obj:item,callbackmethod:""}];	//rowHoverCallBackALARM
	return jsons;
}
function getPosName(item)
{
	return item.szPosition;	
}
////////////////事件或报警上传 开始///////////////////////////
function getRecordsByAllDevices(isEvent,callBackMethod)
{
	if(callBackMethod != undefined)
		g_callBackObjs = callBackMethod;
	setTitleProc(STATUS_POP_WIN_DEFAULT_ID,"",false);
	var ret = null;
	if(isEvent)
		ret = _externalUploadEvent('OnGetRecordItem');
	else
		ret = _externalUploadAlarm('OnGetRecordItem');
	
	eval ('var item = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	//单个设备上传出错：{nCode:0, nType:2, szMsg:"%s"}
	if (item.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作
		return 0;
	}
	
	var oJson = {"mode":item.nLevel,"msg":replaceStr(item.szMsg,"\n","<br/>")};
	insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);
	setTitleProc(STATUS_POP_WIN_DEFAULT_ID,"",true);
}
//回调函数，每得到一条设备信息被调用一次
function OnGetRecordItem(szItem)
{
	eval('var item = ' + szItem);
	var oJson = null;
	/*
	单个设备开始上传：{nCode:0，nType:1，szMsg:"%s"}
单个设备上传出错：{nCode:0, nType:2, szMsg:"%s"}
	*/
	if (item.nCode == 1)//列表线程已启动
	{
		//oJson = {"mode":item.nLevel,"msg":"开始上传数据"};
		//insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);
		return;
	}
	else if (item.nCode == 2)
	{
		delayExecuteCallBackMethod(g_callBackObjs);
		g_callBackObjs = null;
		setTitleProc(STATUS_POP_WIN_DEFAULT_ID,"",true);
		return;
	}
	else if (item.nCode < 0)
	{
		//同时也表示操作错误完成
		oJson = {"mode":item.nType,"msg":replaceStr(item.szMsg,"\n","<br/>")};
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);
	}
	else if (item.nCode == 0)
	{
		oJson = {"mode":item.nType,"msg":replaceStr(item.szMsg,"\n","<br/>")};
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);
		return;
	}
	//else
//		alert("不应该到达此处，说明VC源代码有错误。");
	cancelProcess();
}
function delayExecuteCallBackMethod(callBack)
{
	if(callBack == undefined | callBack == "")
	{
		completeDownloadDataCallBack();//完成后客户手动关闭
		removeTabListStopOperationRow();
		//setTimeout(function(){removePopTabWin();},2000);//定时关闭
		var oJson = {"mode":LOG_SUCCESS_TIPS,"msg":getLanTextByKey("T_TIME_SPAN_COMPLETE_DATA_TIPS")};//"<span style='color:blue;'>"+getLanTextByKey("T_TIME_SPAN_COMPLETE_DATA_TIPS")+"</span>"};
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);
	}
	else if(callBack != null && callBack != "no")
	{
		var aCallBack = callBack.split("(");
		if(checkMethodName(aCallBack[0]) && (!g_isForceExited))
			setTimeout(function(){g_callBackObjs = null;eval(callBack);},5);
		else if(g_isForceExited)
		{
			completeDownloadDataCallBack();//完成后客户手动关闭
			removeTabListStopOperationRow();
		}
	}
	else
	{
		completeDownloadDataCallBack();//完成后客户手动关闭
		removeTabListStopOperationRow();
		//setTimeout(function(){removePopTabWin();},2000);//定时关闭
		var oJson = {"mode":LOG_SUCCESS_TIPS,"msg":getLanTextByKey("T_TIME_SPAN_COMPLETE_DATA_TIPS")};//"<span style='color:blue;'>"+getLanTextByKey("T_TIME_SPAN_COMPLETE_DATA_TIPS")+"</span>"};
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);
	}
}
////////////////事件或报警上传 结束///////////////////////////

function getEventCosSelectName(forceGetSoftwareData)
{
	var isForceGetSoftwareData = false;
	if(forceGetSoftwareData != undefined)
		isForceGetSoftwareData = forceGetSoftwareData;
	var aStyles = sortByaKeyVal(g_event_tab_data_styles,g_event_tab_index,"index",true);
	if(IMPORT_EMPLOYEE_COMPARE_UI_MODE === 1 | isForceGetSoftwareData)
	{		
		var colObj = {"-1":getLanTextByKey("T_NOT_IMPORT_EMP_TIPS")};
		var count = 0;
		for(var j = 0; j < aStyles.length; j++)
		{
			if(aStyles[j]["isDisplay"])
			{
				if(aStyles[j]["id"] !== "")
					colObj[aStyles[j]["key"]] = aStyles[j]["name"];
				
			}
		}	
		//console.log(colObj);
		return colObj;
	}
	else
	{
		var jsons = [];
		for(var j = 0; j < aStyles.length; j++)
		{
			if(aStyles[j]["isDisplay"])
				jsons.push({"cname":aStyles[j]["key"],"text":aStyles[j]["name"]});
		}
		return jsons;
	}
}