//搜索设备（开始）   列出局域网内所有被支持的设备
var COL_SELECT = 0;
var COL_NO = 1;
var COL_NAME = 2;
var COL_MODEL = 3;
var COL_IP = 4;
var COL_MAC = 5;
var COL_PORT = 6;
var COL_VERSION = 7;
var COL_WEEK = 8;
var COL_HOLIDAY = 9;
var COL_OPERATION = 10;

var g_added_device_tab_aIndex = new Array(COL_SELECT,COL_NO,COL_NAME,COL_MODEL,COL_IP,COL_MAC,COL_PORT,COL_VERSION,COL_WEEK,COL_HOLIDAY,COL_OPERATION);

var FINGER_MODE = 1;
var FACE_MODE = 2;
var CARD_MODE = 0;
var FINGER_DEVICE_PARA_KEY = "FingerPrint";
var CARD_DEVICE_PARA_KEY = "CardDevice";
var FACE_DEVICE_PARA_KEY = "FaceDevice";
var g_aDeviceData = null;
var g_sn = -1;
var g_deviceEditStatus = false;
var g_added_device_tab_styles  = null;
var g_maxDeviceNameLength = 30;
/*加信息设备的全局函数*/
var g_aAsAddInfoDevice = null;//发卡设备
var g_aFingerAddInfoDevice = null;//指纹采集设备
var g_aFaceAddInfoDevice = null;//人脸采集设备
var USB_ADD_EMP_INFO_DEVICE_ID = 10000;
var g_aSelectedDoors = [];
var g_aDoorsWeekData = 0;
var g_deviceObj = null;
/*
	//D系列控制器范围
	#define ANSON_DMIN   AS_ME_TYPE_DL_24
	#define ANSON_DMAX   0x10310
	//F系列指纹机范围
	#define ANSON_FMIN   0x10260
	#define ANSON_FMAX   0x10280
	
	//DE系列设备范围
	#define ANSON_DEMIN  0x10215
	#define ANSON_DEMAX  0x10310
	#define AS_ME_TYPE_DE_12       0x10222
	#define AS_ME_TYPE_DE_20       0x10245
	#define AS_ME_TYPE_DE_20IC     0x10246
	#define AS_ME_TYPE_DE_20T      0x10247
	#define AS_ME_TYPE_DE_30T      0x10249
	
	#define AS_ME_TYPE_DF_20       0x10260
	#define AS_ME_TYPE_DF_30       0x10262
	#define AS_ME_TYPE_DF_40       0x10264
	//人脸
  #define ANSON_DEMIN  0x10281
	#define ANSON_DEMAX  0x10310
	#define AS_ME_TYPE_FF_20       0x10281 Face 7M
	#define AS_ME_TYPE_FF_30       0x10282 Face 7L
	#define AS_ME_TYPE_FF_40       0x10283 Face 7
	#define AS_ME_TYPE_FF_50       0x10284 Face 5
	#define AS_ME_TYPE_FF_60       0x10285 Face 5T*/
var g_productInfoObjs = [
  {"nID":1,"DwTypeName":getLanTextByKey("T_ACCESS_CONTROLLER_DEVICE_NAME"),"products":           
                  [{"nID":1,"dwType":0x10222,"szType":getLanTextByKey("T_DEV_NAME_DE12"),"minDwType":0x10215,"maxDwType":0x10310}]
  },
  {"nID":2,"DwTypeName":getLanTextByKey("T_INTEGRATED_ACCESS_CONTROLLER_DEVICE_NAME"),"products":           
                  [
                    {"nID":1,"dwType":0x10245,"szType":getLanTextByKey("T_DEV_NAME_DE20"),"minDwType":0x10215,"maxDwType":0x10310},
                    {"nID":2,"dwType":0x10246,"szType":getLanTextByKey("T_DEV_NAME_DE20IC"),"minDwType":0x10215,"maxDwType":0x10310},
                    {"nID":3,"dwType":0x10245,"dwType":0x10247,"szType":getLanTextByKey("T_DEV_NAME_DE20T"),"minDwType":0x10215,"maxDwType":0x10310},
                    {"nID":4,"dwType":0x10249,"szType":getLanTextByKey("T_DEV_NAME_DE30T"),"minDwType":0x10215,"maxDwType":0x10310}
                  ]
  },
  {"nID":3,"DwTypeName":getLanTextByKey("T_FINGERPRINT_CONTROLLER_DEVICE_NAME"),"products":           
                  [
                    {"nID":1,"dwType":0x10260,"szType":getLanTextByKey("T_DEV_NAME_DF20"),"minDwType":0x10215,"maxDwType":0x10310},
                    {"nID":2,"dwType":0x10262,"szType":getLanTextByKey("T_DEV_NAME_DF30"),"minDwType":0x10215,"maxDwType":0x10310},
                    {"nID":3,"dwType":0x10264,"szType":getLanTextByKey("T_DEV_NAME_DF40"),"minDwType":0x10215,"maxDwType":0x10310}
                  ]
  },
  {"nID":4,"DwTypeName":getLanTextByKey("T_FACIAL_RECOGNITION_CONTROLLER_DEVICE_NAME"),"products":           
                  [
                    {"nID":1,"dwType":0x10281,"szType":getLanTextByKey("T_DEV_NAME_FF20"),"minDwType":0x10215,"maxDwType":0x10310},
                    {"nID":2,"dwType":0x10282,"szType":getLanTextByKey("T_DEV_NAME_FF30"),"minDwType":0x10215,"maxDwType":0x10310},
                    {"nID":3,"dwType":0x10283,"szType":getLanTextByKey("T_DEV_NAME_FF40"),"minDwType":0x10215,"maxDwType":0x10310},
                    {"nID":4,"dwType":0x10284,"szType":getLanTextByKey("T_DEV_NAME_FF50"),"minDwType":0x10215,"maxDwType":0x10310},
                    {"nID":5,"dwType":0x10285,"szType":getLanTextByKey("T_DEV_NAME_FF60"),"minDwType":0x10215,"maxDwType":0x10310},
                    {"nID":5,"dwType":0x10286,"szType":getLanTextByKey("T_DEV_NAME_FF5A"),"minDwType":0x10215,"maxDwType":0x10310},
                    {"nID":5,"dwType":0x10287,"szType":getLanTextByKey("T_DEV_NAME_FF5C"),"minDwType":0x10215,"maxDwType":0x10310}
                  ]
  }
];
function ListAllDevsOnLAN()
{
	//_externalSetOperationDelay(0);	
	g_sn = 1;
	g_aDeviceData = new Array();
	var ret = _externalListAllDevsOnLAN('OnDeviceItemOnLAN');
	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);
}

//回调函数，每得到一条设备信息被调用一次
function OnDeviceItemOnLAN(szItem)
{
	eval('var item = ' + szItem);
	//item.nCode 错误码。为1时表示列表线程开始，其它成员无效，为2时表示线程结束，其它成员无效，为0时表示一行数据除szMsg成员无效外，其它成员都有效。小于0时表示出错，下面的成员除szMsg外都无效
	//item.szMsg 当出错时该成员才有效，包含错误的文本信息。
	//item.nID 设备在数据库中的ID号，当该值 为-1表示设备未加入系统
	//item.dwType 设备类型码
	//item.szType 设备类型显示名
	//item.szName 设备名
	//item.szIP 设备IP地址
	//item.dwPort 端口号
	//item.szSubnetMask 子网掩码
	//item.szIPGate 网关IP地址
	//item.szVersion 版本号
	//item.szMAC 设备MAC地址
	//item.dwFlag 当其第0位置1时表示系统中加入的其它控制器已使用了该IP地址。当其第1位置1时表示搜索到的类型与加入系统的类型不同。当其第2位置1时表示搜索到的IP地址与加入系统的IP地址不同。
	if (item.nCode == 1)//列表线程已启动
	{
		startProcess(1,null);
	}
	else if (item.nCode == 2)
	{/*
		setTimeout(function(){
			var tabIdName = "tab_pop_list_data";
			initInsertRows(tabIdName,gListRowsAmount*30,10,g_aDeviceData,false);			
			cancelProcess();
		},0);*/
		cancelProcess();
		initSearchDeviceList(g_aDeviceData,getLanTextByKey("T_ADD_CONTROLLER_TITLE"));
		g_aDeviceData = null;
	}
	else if (item.nCode < 0)
	{
		showToast(item.szMsg,DIALOG_MASK_TIP_MODE,2);//同时也表示操作错误完成
		setTimeout(function(){removeMask();},2600);
	}
	else if (item.nCode == 0)
	{
		if(!g_startFaceMode)
		{
			var mode = {"minType":0x10281,"maxType":0x10310,"cerMode":new Array("-1","1","13","11","12")};/*人脸*/
			if(item.dwType >=	mode["minType"] && item.dwType <= mode["maxType"])	
			{
				
			}
			else
				g_aDeviceData.push(getSearchDeviceItem(item));
		}
		else
			g_aDeviceData.push(getSearchDeviceItem(item));
		
		/*var info = document.getElementById("Result_Info");
		info.innerHTML += g_sn + " ";
		info.innerHTML += item.nID + " ";
		info.innerHTML += item.dwType + " ";
		info.innerHTML += item.szType + " ";
		info.innerHTML += item.szName + " ";
		info.innerHTML += item.szIP + " ";
		info.innerHTML += item.dwPort + " ";
		info.innerHTML += item.szSubnetMask + " ";
		info.innerHTML += item.szIPGate + " ";
		info.innerHTML += item.szVersion + " ";
		info.innerHTML += item.szMAC + " ";		
		info.innerHTML += item.szAddedType + " ";//已加入系统的设备类型
		info.innerHTML += item.szAddedIP + " ";//已加入系统的IP地址
		if (item.nID >= 0)
			info.innerHTML += "已加入 ";
		if (item.dwFlag & 1)
			info.innerHTML += "IP被使用 ";
		if (item.dwFlag & 2)
			info.innerHTML += "类型不同 ";
		info.innerHTML += "<input type=\"button\" name=\"button\"  value=\"添加\"  onclick=\"AddDevice(" + (g_sn - 1) + ");\"/><br/>";*/
	}
	else
		alert("不应该到达此处，说明VC源代码有错误。");
}
function getSearchDeviceItem(item)
{
	var obj = getColorByFlag(item.dwFlag);
	return [{"index":COL_SELECT,"val":getCheckBoxById(item.nID,"cb_search_device_","searchDeviceCallBack")},{"index":COL_NO,"val":g_sn++},{"index":COL_NAME,"val":item.szName},{"index":COL_MODEL,"val":item.szType},{"index":COL_IP,"val":item.szIP},{"index":COL_MAC,"val":item.szMAC},{"index":COL_PORT,"val":item.dwPort},{"index":COL_VERSION,"val":item.szVersion},{"index":COL_OPERATION,"val":getSearchDeviceRowOperateBtns(getLanTextByKey("T_COMUNICATION_SETUP_TITLE"),getLanTextByKey("T_ADD_CONTROLLER_TITLE"),"editSearcheddDevice","AddDevice",item,obj.tips)},{"condition":0,"trBkColor":obj.color,"tips":obj.tips,obj:item}];	
}
function getColorByFlag(flag)
{
	var obj = new Object();
	obj.color = "";
	obj.tips = "";
	if(flag & 1)
	{
		obj.color = BK_COLOR_WARNNING;
		obj.tips = getLanTextByKey("T_OCCUPY_IP_ADDRESS_DESC");
	}
	
	if(flag & 2)
	{
		obj.color = BK_COLOR_WARNNING;
		obj.tips += ((obj.tips.length > 0)?"<br/>":"") + getLanTextByKey("T_TYPE_NOT_SYNC_DESC");
	}
	
	if(flag & 4)
	{
		obj.color = BK_COLOR_WARNNING;
		obj.tips += ((obj.tips.length > 0)?"<br/>":"") + getLanTextByKey("T_IP_ADDRESS_NOT_SYNC_DESC");
	}
	
	//obj.color = (flag & 1)?BK_COLOR_WARNNING:obj.color;	
	//obj.color = ((flag & 2)  & (obj.color != BK_COLOR_WARNNING))?BK_COLOR_WARNNING:obj.color;	
	//obj.color = ((flag & 4)  & (obj.color != BK_COLOR_WARNNING))?BK_COLOR_WARNNING:obj.color;	
	//obj.tips = (flag & 1)?getLanTextByKey("T_OCCUPY_IP_ADDRESS_DESC"):"";
	//obj.tips = ((flag & 2) & (obj.tips == ""))?getLanTextByKey("T_TYPE_NOT_SYNC_DESC"):"";
	//obj.tips = ((flag & 4) & (obj.tips == ""))?getLanTextByKey("T_IP_ADDRESS_NOT_SYNC_DESC"):"";
	return obj;
}
function getSearchDeviceRowOperateBtns(editTips,delTips,editMethodName,addMethodName,item,tips)
{
	var id = replaceStr(item.szMAC," ","");
	var pack = document.createElement("div");
	pack.style.cssText = "width:120px;overflow:hidden;";
	var editBtn = createAbtn("icon_edit icobtn",editTips,editMethodName);
	editBtn.id = "btn_edit_" + id;
	editBtn.style.cssText = "padding-top:7px;width:36px;margin-left:6px;";
	var addBtn = createAbtn("icon_add_search_device icobtn",((item.nID == -1)?delTips:getLanTextByKey("T_ADDED_DEVICE_RETRY_TIPS")),addMethodName);
	addBtn.style.cssText = "padding-top:7px;padding-left:9px;width:36px;background-color:#"+((item.nID == -1)?SUCCESS_COLOR+";cursor:pointer;":DISABLED_BK_COLOR+";cursor:default;")+";";
	addBtn.disabled = (item.nID == -1)?false:true;
	addBtn.id = "btn_add_" + id;
	pack.appendChild(addBtn);
	pack.appendChild(editBtn);
	
	var isFace = checkDeviceType(item.dwType,FACE_MODE);
	var nTips = ((item.nID != -1 && tips == "")?getLanTextByKey("T_UPDATE_DEVICE_TIPS"):getLanTextByKey("T_NOT_UPDATE_DEVICE_TIPS"));
	if(!isFace)
		nTips = getLanTextByKey("T_NOT_SUPPORT_UPDATE_DEVICE_TIPS");
	var updateBtn = createAbtn("icon_update_search_device icobtn",nTips,"getFilePath");
	updateBtn.style.cssText = "margin-left:4px;padding-top:7px;padding-left:9px;width:36px;background-color:#"+((item.nID != -1 && tips == "" && isFace)?ALAM_BK_COLOR+";cursor:pointer;":DISABLED_BK_COLOR+";cursor:default;")+";";
	updateBtn.disabled = (item.nID != -1 && tips == "" && isFace)?false:true;
	updateBtn.id = "btn_update_" + id;
	pack.appendChild(updateBtn);
	//pack.appendChild(queryPhotoBtn);
	return pack;
}
function getFilePath(btnDiv)
{
	if(btnDiv == null | btnDiv.disabled)
		return;
	var vStr = "All Supported Formats(*.bz2)|"
													+ "*.bz2;|";
	var ret = getSelectFilePath(vStr,getLanTextByKey("T_PLS_SELECT_UPDATE_DEVICE_FILE_TIPS"));
	console.log("ret = "+ret);
	if(ret == null)
		return;
	else
		 updateDeviceProgram(btnDiv,ret);
	//filterFileByName(fName,new Arry("biz2"));
}
function updateDeviceProgram(btnDiv, strFileFullPathName)
{
	btnDiv.disabled = true;
	var row = getFirstParentObjByTag(btnDiv,"tr");
	var item = row.hideContent;
	g_item = item;
	g_control = btnDiv;
	startProcess(4,null);
	//console.log(item);
	//console.log("strFileFullPathName = "+strFileFullPathName + ",item.id="+item.nID);
	
	var ret = _externalUpdateDevice("onUpdateDevice", item.nID, strFileFullPathName);
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作
		return 0;
	}
	else
	{
		cancelProcess(null,4);
		showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);
		g_control.disabled = false;
		g_control = null;
	}
}
function onUpdateDevice(szRet)
{	
	eval('var err = ' + szRet);
	//err.nCode 错误码。大于等于0时表示无错误且为设备的ID号。szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	//err.szName 仅当nCode大于等于0时有效，表示增加后的设备名。
	console.log(szRet);
	var times = 0;
	if (err.nCode >= 0)
	{
		//g_control.style.backgroundColor = "#ccc";
		//objMousePropertySetNull(g_control);	
		times = parseInt(err.nCode,10);
	}
	else	
		setTimeout(function(){showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);},100);
	//console.log("times="+times);
	g_item = null;
	setTimeout(function(){
		cancelProcess(null,4);
		if(g_control != null)
			g_control.disabled = false;
		g_control = null;	
	},times*1000);
	
}
//搜索设备（结束）   
function AddDevice(btnDiv)
{
  var item = null;
	if(isListingDeviceAndDoor)
		return;
  if(btnDiv.params == undefined)
  {
    if(btnDiv == null | btnDiv.disabled)
		return;
    btnDiv.disabled = true;
    var row = getFirstParentObjByTag(btnDiv,"tr");
    item = row.hideContent;
  }
  else
    item = btnDiv.hideContent;
	
	g_item = item;
	g_control = btnDiv;
	startProcess(4,null);
 // setTimeout(function(){delaySetMask();},300);
  //console.log(item.szMAC+", " + item.dwType+", " + item.szIP+", " + item.dwPort);
	var ret = _externalAddDevice('onAddDevice', item.szMAC/*szMAC*/, item.dwType/*dwType*/, item.szIP/*szIP*/, item.dwPort/*dwPort*/);
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作
		return 0;
	}
	else
	{
		cancelProcess(null,4);
		showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);
		g_control.disabled = false;
		g_control = null;
	}
	
}
function onAddDevice(szRet)
{	
	eval('var err = ' + szRet);
	//err.nCode 错误码。大于等于0时表示无错误且为设备的ID号。szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	//err.szName 仅当nCode大于等于0时有效，表示增加后的设备名。
	
	if (err.nCode >= 0)
	{
    if(g_control.style != undefined)
    {
      g_control.style.backgroundColor = "#"+DISABLED_BK_COLOR;
      objMousePropertySetNull(g_control);		
      var row = getFirstParentObjByTag(g_control,"tr");
      (row.hideContent).nID  = err.nID;
      setTimeout(function(){
        cancelProcess(null,4);
        var updateBtn = childNodesByIdStrBlurQuery(g_control,"update");
        var isFace = checkDeviceType(err.dwType,FACE_MODE);
        if(updateBtn != null && isFace)
        {
          updateBtn.style.cssText = "padding-top:7px;padding-left:9px;margin-left:4px;width:36px;background-color:#ff0000;color:#fff;cursor:pointer;";
          updateBtn.tips = getLanTextByKey("T_UPDATE_DEVICE_TIPS");
          setIcoAbtnStatus(updateBtn,false);
          setEasyUITooltips(updateBtn,'top');
        }
        g_control = null;
        callBackModifyNameByRes(err,false);
        g_item = null;	
      },50);
    }
    else
    {
      cancelProcess(null,4);
      callBackModifyNameByRes(err,true);
      g_item = null;	
    }
	}
	else
	{
		g_item = null;
		cancelProcess(null,4);
		showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);
		g_control.disabled = false;
	}
	
}
function childNodesByIdStrBlurQuery(btn,idStr)
{
	var pNode = btn.parentNode;
	for(var i = 0; i < pNode.childNodes.length; i++)
	{
		if(((pNode.childNodes)[i].id).indexOf(idStr) > -1)
			return 	(pNode.childNodes)[i];
	}
	return null;
}
//更改IP地址代码////////////////////////////////////////////////////////////////////////////
function modifySearchDeviceIp(btn)
{
	var ipObj = document.getElementById("txt_searched_device_ip");
	if(!checkIP(ipObj.value))
	{
		showToast(getLanTextByKey("T_PLS_INPUT_RIGHT_IP_ADDRESS_DESC"),DIALOG_MASK_TIP_MODE,2);
		ipObj.focus();
		return;
	}
	var portObj = document.getElementById("txt_searched_device_port");
	var subnetmaskObj = document.getElementById("txt_searched_device_subnetmask");	
	if(!checkMask(subnetmaskObj.value))
	{
		showToast(getLanTextByKey("T_PLS_INPUT_RIGHT_SUBMASK_DESC"),DIALOG_MASK_TIP_MODE,2);
		return;
	}
	var gateObj = document.getElementById("txt_searched_device_gate");
	if(!checkIP(gateObj.value))
	{
		showToast(getLanTextByKey("T_PLS_INPUT_RIGHT_GATE_ADDRESS_DESC"),DIALOG_MASK_TIP_MODE,2);
		return;
	}
	var isSubmit = false;
	var item = btn.hideContent;
	if(item.szIP != ipObj.value)
	{
		item.nszIP = ipObj.value;
		isSubmit = true;
	}
	else
		item.nszIP = item.szIP;
	//alert("szIP-"+(item.szIP != ipObj.value));
	if(item.dwPort != parseInt(portObj.value))
	{
		item.ndwPort = parseInt(portObj.value);
		isSubmit = true;
	}
	else
		item.ndwPort = item.dwPort;
	//alert("dwPort-"+(item.dwPort != parseInt(portObj.value)));
	if(item.szSubnetMask != subnetmaskObj.value)
	{
		item.nszSubnetMask = subnetmaskObj.value;
		isSubmit = true;
	}
	else
		item.nszSubnetMask = item.szSubnetMask;
	//alert("szSubnetMask-"+(item.szSubnetMask != subnetmaskObj.value));
	if(item.szIPGate != gateObj.value)
	{
		item.nszIPGate = gateObj.value;
		isSubmit = true;
	}
	else
		item.nszIPGate = item.szIPGate;
	//alert("szIPGate-"+(item.szIPGate != gateObj.value)+",,"+item.szIPGate.length+" : "+item.szIPGate+",,text:"+gateObj.value.length+" : "+gateObj.value);
	if(!isSubmit)
	{
		ipObj.focus();
		return;
	}
	g_item = item;
	
	/*(g_sn++),
					item.szType,
					item.dwType,
					item.szIP,
					item.nID,
					item.szName,
					item.szSubnetMask,
					item.szIPGate,
					item.szMAC,
					item.dwPort, 
					item.szVersion,
					btnStr));*/
	//console.log("网关="+item.nszIPGate+",掩码= "+item.nszSubnetMask+", 端口="+item.ndwPort+", IP="+ipObj.value+",initIP="+item.nszIP+", szMAC="+item.szMAC+", nID="+item.nID);
	//var ret = _externalChangeDevIP('192.168.0.1', '255.255.255.0', g_Items[nIdx].dwPort, '192.168.0.89', g_Items[nIdx].szMAC,  g_Items[nIdx].nID, 'onChangeDevice');
	startProcess(4,null);
	var ret = _externalChangeDevIP('onChangeDevice', item.nID/*nID*/, item.szMAC/*MAC*/, item.nszIP/*IP*/, item.ndwPort/*端口*/, item.nszSubnetMask/*掩码*/, item.nszIPGate/*网关*/);
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作
		
		return 0;
	}
	
	cancelProcess(null,4);
	showToast(err.szMsg,2,2);
	g_item = null;
}
function onChangeDevice(szRet)
{
	eval('var err = ' + szRet);
	//err.nCode 错误码。大于等于0时表示无错误且为设备的ID号。szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode < 0)
	{
		cancelProcess(null,4);
		showToast(err.szMsg,2,2);
		g_item = null;
	}
	else
	{
		setTimeout(function(){
				g_item.szIP = g_item.nszIP;
				g_item.dwPort = g_item.ndwPort;
				g_item.szSubnetMask = g_item.nszSubnetMask;
				g_item.szSubnetMask = g_item.nszSubnetMask;
				g_item.szIPGate = g_item.nszIPGate;
				callBackModifyIPByRes(g_item);	
				g_callBackObjs = null;
				g_item = null;
				removePopTabWin("pop_search_device_edit_win",4);
				
				},50);
	}
}
//删除设备代码////////////////////////////////////////////////////////////////////////////
function confirmDelDevice(btn)
{
	if(btn.disabled)
		return;
	btn.disabled = true;
	g_control = getFirstParentObjByTag(btn,"tr");
	var item = g_control.hideContent;
	var sConfirm = new customConfirm();
	sConfirm.init(getLanTextByKey("T_CONFIRM_TIPS").replace("%1",'<span style="color:#cd1a1a;">\"' + item.szName + '\"</span>'),"callBackConfirmDelDevice");
	btn.disabled = false;
}
function callBackConfirmDelDevice(isDel)
{
	if(isDel)
		DelDevice();
}
function DelDevice()
{
	if(g_control == null | g_control.hideContent == undefined | g_control.hideContent == null)
		return;
	var item = g_control.hideContent;
	var ret = _externalDelDevice('onDelDevice',item.nID);
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作		
		startProcess(1,null);
		return 0;
	}
	else
	{
		showToast(err.szMsg,2,2);
		g_control = null;
	}
}

function onDelDevice(szRet)
{
	eval('var err = ' + szRet);
	//err.nCode 错误码。大于等于0时表示无错误且为设备的ID号。szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	cancelProcess();	
	if (err.nCode < 0)
	{
		showToast(err.szMsg,2,2);
		g_control = null;
	}
	else
	{
		setTimeout(function(){queryDeviceAndDoor();},500);
		//(g_control.parentNode).removeChild(g_control);
		g_control = null;
	}
}
//修改设备代码////////////////////////////////////////////////////////////////////////////
var CTRL_IDX_NAME = 1 << 1;
var CTRL_IDX_DEV_TYPE = 1 << 2;
var CTRL_IDX_DOOR_NUM = 1 << 3;
var CTRL_IDX_RDR_PROTOCOL = 1 << 4;
var CTRL_IDX_ADDRESS = 1 << 5;
var CTRL_IDX_PORT = 1 << 6;
var CTRL_IDX_LCDNAME = 1 << 7;
//var CTRL_IDX_MAX = 8;
function modifyAddedDeviceName(btn)
{
	if(btn.disabled)
		return;	
	var dwMask = 0;
	var deviceMask = 0;
	var editObj = document.getElementById(TABLE_ROW_EDIT_ID+"_device");
	var item = editObj.hideContent[0];//alert(JSON.stringify(item));
	var nItem = editObj.hideContent[1][0];
  console.log(nItem);
  console.log(item);
	var advItem = editObj.hideContent[2];
	var cItem = new Object();
	
	var deviceObj = document.getElementById("txt_device_name");
	cItem.szName = deviceObj.value;
	if(deviceObj.tips == deviceObj.value | deviceObj.tips == "")
	{
		showToast(getLanTextByKey("PLS_INPUT_DEVICE_NAME_DESC"),2,2);
		return;
	}
	else if(item.szName != cItem.szName)
  {
    deviceMask |= CTRL_IDX_NAME;
		if(g_bDebugMode)console.log("设置设备名称智能下载标识szName：" + CTRL_IDX_NAME + ",新设置设备名称: "+cItem.szName+", deviceMask = "+deviceMask);
  }
		
	
	var lockDelayObj = document.getElementById("txt_lock_delay");
	cItem.dwLockDelay = lockDelayObj.value;	
	
	if(nItem.dwLockDelay != parseInt(cItem.dwLockDelay,10))
	{
		dwMask |= DOOR_IDX_LOCK_DELAY;
		if(g_bDebugMode)console.log("设置门dwLockDelay载标识dwMask：" + DOOR_IDX_LOCK_DELAY + ",新设置dwLockDelay: "+cItem.dwLockDelay+", dwMask = "+dwMask);
		nItem.dwLockDelay = parseInt(cItem.dwLockDelay,10);
	}
	
	cItem.dwLockRelay = $('#txt_dwLock_relay').combobox('getValue');	
	cItem.dwLockRelayTxt = $('#txt_dwLock_relay').combobox('getText');
	if(nItem.dwLockRelay != parseInt(cItem.dwLockRelay,10))
	{
		dwMask |= DOOR_IDX_LOCK_RELAY;
		if(g_bDebugMode)console.log("设置门门锁继电器智能下载标识dwMask：" + DOOR_IDX_LOCK_RELAY + ",新设置时时长: "+cItem.dwLockRelay+", dwMask = "+dwMask);
		nItem.dwLockRelay = parseInt(cItem.dwLockRelay,10);
	}
	
	cItem.dwLatchMode = $('#txt_door_mode').combobox('getValue');	
	cItem.dwLatchModeTxt = $('#txt_door_mode').combobox('getText');
	if(nItem.dwLatchMode != parseInt(cItem.dwLatchMode,10))
	{
		dwMask |= DOOR_IDX_OPEN_MODE;
		if(g_bDebugMode)console.log("设置门dwLatchMode下载标识dwMask：" + DOOR_IDX_OPEN_MODE + ",新设置dwLatchMode: "+cItem.dwLatchMode+", dwMask = "+dwMask);
		nItem.dwLatchMode = parseInt(cItem.dwLatchMode,10);
	}
	
	cItem.dwSwitchType = $('#txt_button_type').combobox('getValue');	
	cItem.dwSwitchTypeTxt = $('#txt_button_type').combobox('getText');
	if(nItem.dwSwitchType != parseInt(cItem.dwSwitchType,10))
	{
		dwMask |= DOOR_IDX_SWITCH_TYPE;
		if(g_bDebugMode)console.log("设置门开超时智能下载标识dwMask：" + DOOR_IDX_SWITCH_TYPE + ",新设置时时长: "+cItem.dwSwitchType+", dwMask = "+dwMask);
		nItem.dwSwitchType = parseInt(cItem.dwSwitchType,10);
	}
	
	cItem.dwSensorType = $('#txt_magnetic_type').combobox('getValue');	
	cItem.dwSensorTypeTxt = $('#txt_magnetic_type').combobox('getText');	
	if(nItem.dwSensorType != parseInt(cItem.dwSensorType,10))
	{
		dwMask |= DOOR_IDX_SENSOR_TYPE;
		nItem.dwSensorType = parseInt(cItem.dwSensorType,10);
	}	
	
	var openTimeoutObj = document.getElementById("txt_open_timeout");
	cItem.dwOpenTimeout = openTimeoutObj.value;	
	if(nItem.dwOpenTimeout != parseInt(cItem.dwOpenTimeout,10))
	{
		dwMask |= DOOR_IDX_OPEN_TIMEOUT;
		if(g_bDebugMode)console.log("设置门开超时智能下载标识dwMask：" + DOOR_IDX_OPEN_TIMEOUT + ",超时: "+cItem.dwOpenTimeout+", dwMask = "+dwMask);		
		nItem.dwOpenTimeout = parseInt(cItem.dwOpenTimeout,10);
	}
	
	cItem.dwRdAuthMode1 = $('#txt_reader1_cer_mode').combobox('getValue');	
	cItem.dwRdAuthMode1Txt = $('#txt_reader1_cer_mode').combobox('getText');
	if(nItem.dwRdAuthMode1 != parseInt(cItem.dwRdAuthMode1,10))
	{
		dwMask |= DOOR_IDX_RD1_AUTH_MODE;
		dwMask |= DOOR_IDX_RD2_AUTH_MODE;
		nItem.dwRdAuthMode1 = parseInt(cItem.dwRdAuthMode1,10);
		nItem.dwRdAuthMode2 = nItem.dwRdAuthMode1;
		if(g_bDebugMode)console.log("设置门开超时智能下载标识dwMask(1-2)：" + DOOR_IDX_RD1_AUTH_MODE + ",读卡器模式: "+cItem.dwRdAuthMode1+", dwMask = "+dwMask);
	}	
	/*
	nInType 为1表示输入常开，为0为常闭。 缺省加入的设备默认为1
nOutMode 为0时表示输出与输入同步，为1时表示延时报警。 缺省加入的设备默认为0
nAlarmDelay 表示报警延时。取值0至255（秒）。缺省加入的设备默认为0
	修改设备时在原来的基础上增加了4个参数，如果不加入这4个参数与原来的版本相同。否则加入这4个参数表示要修改报警。
_externalModifyDevice(..., nAlarmMask, nInType, nOutMode, nAlarmDelay),最后的三个参数的含义请参考上面的信息。
nAlarmMask为1时表示修改了nInType, 为2时表示修改了nOutMode,为4时表示修改了nAlarmDelay
	*/
	nItem.nAlarmMask = 0;
	if(g_isDisplayAlarmSetup)
	{
		cItem.nInType = $('#sele_in_type').combobox('getValue');	
		cItem.nInTypeTxt = $('#sele_in_type').combobox('getText');	
		if(nItem.nInType != parseInt(cItem.nInType,10))
		{
			nItem.nAlarmMask |= 1;
			nItem.nInType = parseInt(cItem.nInType,10);
		}	
		
		cItem.nOutMode = $('#sele_out_mode').combobox('getValue');	
		cItem.nOutModeTxt = $('#sele_out_mode').combobox('getText');	
		if(nItem.nOutMode != parseInt(cItem.nOutMode,10))
		{
			nItem.nAlarmMask |= 2;
			nItem.nOutMode = parseInt(cItem.nOutMode,10);
		}	
		
		var alarmTimeoutObj = document.getElementById("txt_alarm_delay_time");
		cItem.nAlarmDelay = alarmTimeoutObj.value;	
		if(item.nAlarmDelay != parseInt(cItem.nAlarmDelay,10))
		{console.log(item.nAlarmDelay + " != " + parseInt(cItem.nAlarmDelay,10));
			item.nAlarmMask |= 4;
			if(g_bDebugMode)console.log("设置延时(秒)：" + cItem.nAlarmDelay + ",新设置时长: "+cItem.nAlarmDelay);		
			item.nAlarmDelay = parseInt(cItem.nAlarmDelay,10);
		}
	}
	
	if(document.getElementById("txt_is_display_emp_name_sele") != null)
	{
		cItem.nLCDName = $('#txt_is_display_emp_name_sele').combobox('getValue');	
		cItem.nLCDNameTxt = $('#txt_is_display_emp_name_sele').combobox('getText');
		
		if(item.nLCDName != parseInt(cItem.nLCDName,10))
		{
			item.nLCDName = parseInt(cItem.nLCDName,10);
			deviceMask |= CTRL_IDX_LCDNAME;
      if(g_bDebugMode)console.log("设置人脸人名显示deviceMask：" + CTRL_IDX_LCDNAME + ",新设置人脸人名: "+cItem.nLCDName+",deviceMask="+deviceMask);	
		}
	}
	else
	{
		cItem.nLCDName = 1;
		deviceMask |= CTRL_IDX_LCDNAME;
	}	
  var dwReader = getDwReader($('#txt_wg_input').combobox('getValue'));
	cItem.dwReader = dwReader["dwReader"];//($('#txt_wg_input').combobox('getValue') === "0")?0:0x40000000;	
  cItem.dwReaderEx = dwReader["dwReaderEx"];
	cItem.dwReaderTxt = $('#txt_wg_input').combobox('getText');	
	if(nItem.dwReader != parseInt(cItem.dwReader,10))
	{
		deviceMask |= CTRL_IDX_RDR_PROTOCOL;
		nItem.dwReader = parseInt(cItem.dwReader,10);
    if(g_bDebugMode)console.log("设置微耕协议deviceMask：" + CTRL_IDX_RDR_PROTOCOL + ",新设置微耕协议低位: "+cItem.dwReader+ ",新设置微耕协议高位: "+cItem.dwReaderEx+",deviceMask="+deviceMask);	
	}	
	nItem.dwMask = dwMask;
	g_item = new Object();
	g_item.item = item;
	g_item.cItem = cItem;
	g_item.nItem = nItem;
	
	startProcess(4,null);
	g_startProc = false;
	var ret = null;
  //console.log("========cItem========");
  //console.log(cItem);
  //console.log("========item========");
  //console.log(item);
  //console.log("deviceMask = " + deviceMask);
	//console.log(item.nID+"/*ID*/, "+cItem.szName+"/*名称*/, "+item.szIP+"/*IP*/, "+item.dwPort+"/*端口号*/, "+cItem.dwReader+"/*读头协议低位*/,"+cItem.dwReaderEx+"/*读头协议高位*/,deviceMask="+deviceMask+", nLCDName="+item.nLCDName+", "+nItem.nAlarmMask+", "+cItem.nInType+", "+cItem.nOutMode+", 时长："+ cItem.nAlarmDelay);
  //console.log(cItem.szName + ",cItem.dwReader: " + (cItem.dwReader).toString(16));

	if(nItem.nAlarmDelay <= 0)
		ret = _externalModifyDevice('onModifyDevice', item.nID/*ID*/, cItem.szName/*名称*/, item.szIP/*IP*/, item.dwPort/*端口号*/, cItem.dwReader/*读头协议*/,cItem.dwReaderEx/*读头扩展协议*/,deviceMask,cItem.nLCDName);
	else
		ret = _externalModifyDevice('onModifyDevice', item.nID/*ID*/, cItem.szName/*名称*/, item.szIP/*IP*/, item.dwPort/*端口号*/, cItem.dwReader/*读头协议*/,cItem.dwReaderEx/*读头扩展协议*/,deviceMask,cItem.nLCDName,nItem.nAlarmMask, cItem.nInType, cItem.nOutMode, cItem.nAlarmDelay);
	//var ret = _externalModifyDevice(aParas[8], aParas[7], aParas[3], deviceName, aParas[4], 'onModifyDevice');
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作
		return 0;
	}
	g_startProc = true;
	cancelProcess(null,4);
	g_control = null;
	setTimeout(function(){showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);},1000);
}
function getDwReader(dwReader)
{
  var nRes = {};
  if(dwReader === "0")
  {
    nRes = {"id":0,"num":26};
  }
  else if(dwReader === "1")
  {
    nRes = {"id":1,"num":34};
  }
  else
  {
    nRes["id"] = dwReader;
    nRes["num"] = parseInt(document.getElementById("txt_reader_protocol_custom_unit").value,10);
    if(nRes["num"] == 26)
      nRes["id"] = 0;
    else if(nRes["num"] == 34)
      nRes["id"] = 1;    
  }//console.log("dwReader="+dwReader+",res = "+getDwMaxValByUnit(nRes));
  return getDwMaxValByUnit(nRes);
}
function getDwMaxValByUnit1(json)
{
  var res = parseInt(json["id"],10) << 30;
  res |= parseInt(json["num"],10) << 24;
  res |= parseInt(json["num"],10) << 18;
  return res;
}
function getDwMaxValByUnit(json)
{
  /*
  dwReader为0~31位
  dwReaderEx为32~63位，其中52至63固定为0

  0~51位含义如下：
  30~31位 为0表示W26，1表示W34，2表示自定义，3表示W66。仅当本值为2时，下面的数据才有意义
  32~35,0~5位表示校验1位置：请固定设为1
  36~39,6~11校验2位置：请设为总位数
  40~43,12~17校验位3位置：全设为0。
  44~47,18~23有效数据位数：请设为总位数-2
  48~51,24~29数据位数
  */
  var nValidBits = json["num"] - 2;
  var nCheck2 = json["num"];
  var obj = {};
  //console.log("韦根设置:"+json["id"]+", 总位数:" + nCheck2);
  obj["dwReaderEx"] = 0;
  obj["dwReader"] = (json["id"] << 30) & 0xC0000000;
  
  obj["dwReaderEx"] |= (nCheck2 & 0x3C0) >> 2;
  obj["dwReaderEx"] |= (nValidBits & 0x3C0) << 6;
  obj["dwReaderEx"] |= (json["num"] & 0x3C0) << 10;

  obj["dwReader"] |= 1;// check1的序号
  obj["dwReader"] |= (nValidBits & 0x3f) << 18;
  obj["dwReader"] |= (json["num"] & 0x3f) << 24;
 
  return obj;
}
//修改设备代码////////////////////////////////////////////////////////////////////////////
function onModifyDevice(szRet)
{
	eval('var err = ' + szRet);
	//err.nCode 错误码。大于等于0时表示无错误且为设备的ID号。szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode < 0)
	{
		g_startProc = true;
		cancelProcess(null,4);
		setTimeout(function(){showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);},1000);
	}
	else
	{
		callBackModifyDeviceNameByRes(g_item);
		g_item = null;
		g_control = null;
		cancelProcess(null,4);
		
	}
	
}
function editAddedDevice(btn)
{
	var tr = getFirstParentObjByTag(btn,"tr");
	var item = tr.hideContent;
	
	initEditRowUI(item,tr.doorHideContent,tr.advHideContent);
}
var DOOR_IDX_LOCK_RELAY = (1 << 2);//门锁继电器
var DOOR_IDX_LOCK_DELAY = (1 << 3);//门锁延时时间
var DOOR_IDX_OPEN_MODE = (1 << 4);//开门模式
var DOOR_IDX_SWITCH_TYPE = (1 << 5);//出门按钮类型
var DOOR_IDX_SENSOR_TYPE = (1 << 7);//门磁类型
var DOOR_IDX_OPEN_TIMEOUT = (1 << 8);//门开超时时长，取值0至50
var DOOR_IDX_RD1_AUTH_MODE = (1 << 10);//读头1的认证模式
var DOOR_IDX_RD2_AUTH_MODE = (1 << 14);//读头2的认证模式
function modifyDoorParas(dwMask,item)
{
	//var dwMask = 0;
	console.log(item);
	var ret = _externalModifyDoor('onModifyDoor', 
																	dwMask/*修改项掩码，IDX索引值参考enum DOOR_INDEX*/,
																	item.nID/*门或设备ID*/,
																	item.szName/*门名，注意不是设备名*/,
																	item.dwLockRelay,
																	item.dwLatchMode/*很重要！开门模式。0表示普通模式。1表示门栓模式。2表示有效认证开门后门在门可开时段内不关闭。3表示门在可开时段内自动打开*/,
																	item.dwSwitchType/*出门按钮类型。0表示常闭，1表示常开*/,
																	item.dwSwitchTime,
																	item.dwSensorType/*门磁类型。0表示常闭，1表示常开，注意：界面上应与门开超时放在一起*/,
																	item.dwLockDelay/*很重要!门锁延时，取值0至255*/,
																	item.dwOpenTimeout/*门开超时时长，取值0至50*/,
																	item.nRdID1/*读头1的ID*/,
																	item.szRdName1,
																	item.dwRdAuthMode1/*很重要！读头1的认证模式。修改这个参数必须同时修改下面读头2对应的参数*/,
																	item.dwRdFirstAuth1,
																	item.szRdUrgencyCode1,
																	item.nRdID2,
																	item.szRdName2,
																	item.dwRdAuthMode2,
																	item.dwRdFirstAuth2,
																	item.szRdUrgencyCode2,
																	item.nReader
																	);
	//var ret = _externalModifyDevice(aParas[8], aParas[7], aParas[3], deviceName, aParas[4], 'onModifyDevice');
	//var ret = _externalModifyDoor(aParas[8], aParas[7], aParas[3], deviceName, aParas[4], 'onModifyDevice');
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作
		
		return 0;
	}
	cancelProcess(null,4);
	g_control = null;
	showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);
}
//修改设备代码////////////////////////////////////////////////////////////////////////////
function onModifyDoor(szRet)
{
	eval('var err = ' + szRet);
	//err.nCode 错误码。大于等于0时表示无错误且为设备的ID号。szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode < 0)
		showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);
	else
	{
		//g_control.childNodes[ADDED_DEVICE_TAB_COL_NAME_INDEX].innerText = document.getElementById("txt_device_name").value;
		//(g_control.parentNode).removeChild(g_control.nextSibling);
		var jsons = [];
		jsons.push(err);
		
		isDialogAddDeviceCallBack = true;
		setTimeout(function(){callBackPage(jsons);},500);
		executeModifyAdvParas({"nID":err.nID},false,false);
		g_control = null;
	}
	cancelProcess(null,4);
}
//列出所有已加设备代码（开始）////////////////////////////////////////////////////////////////////////////
var g_aCurrentDeviceData = null;
var g_currentDeviceAmount = 0;
var g_deviceTypeId = -1;
var g_callBackListAllDevsObjs = null;
function ListAllDevs(typeId,callBackMethod)
{
	g_currentDeviceAmount = 0;
	if(typeId == undefined)
		typeId = -1;
	
	if(callBackMethod != undefined)
		g_callBackObjs = callBackMethod;
	else
		g_callBackObjs = null;
	g_callBackListAllDevsObjs = g_callBackObjs;
	startProcess();
	
	g_deviceTypeId = typeId;
	g_sn = 0;
	g_aCurrentDeviceData = new Array();
	
	var ret = _externalListAllDevs('OnDeviceItem', typeId/*-1表示所有设备。0发卡设备1表示所有指纹机*/);
	eval ('var err = ' + ret);
	
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作		
		return 0;
	}
	else
	{
		g_callBackObjs = null;
		g_deviceTypeId = -1;
		cancelProcess();
		setTimeout(function(){showToast(err.szMsg,GENERAL_ALARM_MODE,2);},200);
	}
}
//回调函数，每得到一条设备信息被调用一次
function OnDeviceItem(szItem)
{
	eval('var item = ' + szItem);
	//item.nCode 错误码。为1时表示列表线程开始，其它成员无效，为2时表示线程结束，其它成员无效，为0时表示一行数据除szMsg成员无效外，其它成员都有效。小于0时表示出错，下面的成员除szMsg外都无效
	//item.szMsg 当出错时该成员才有效，包含错误的文本信息。
	//item.nID 设备在数据库中的ID号
	//item.dwType 设备类型码
	//item.szType 设备类型显示名
	//item.szName 设置名
	//item.szIP 设备IP地址
	//item.dwPort 端口号
	//item.dwReader 读头协议
	//item.szMAC 设备MAC地址
	if (item.nCode == 1)//列表线程已启动
	{
		return;
	}
	else if (item.nCode == 2)
	{
		g_currentDeviceAmount = g_aCurrentDeviceData.length;
		if(g_isInitListUI)
		{
			if(typeof initAddedDeviceList != 'undefined')
				setTimeout(function(){initAddedDeviceList(g_aCurrentDeviceData);g_aCurrentDeviceData = null;},50);
			
			cancelProcess();
			if(g_callBackObjs != null)
				eval(g_callBackListAllDevsObjs);
			return;
		}
		
		if(g_callBackListAllDevsObjs != null)
			g_callBackListAllDevsObjs();
		
		if(checkIsFuncList())
			callTailOfFuncList();
		
		//g_callBackObjs = null;
		g_deviceTypeId = -1;
		return;
	}
	else if (item.nCode < 0)
	{
		setTimeout(function(){showToast(item.szMsg,GENERAL_ALARM_MODE,2);delaySetMask();},200);
		//同时也表示操作错误完成
		g_deviceTypeId = -1;
		
		//g_callBackObjs = null;
	}
	else if (item.nCode == 0)
	{
		var obj = getAddedDeviceItemObj(++g_sn,item,"editAddedDevice");
		g_aCurrentDeviceData.push(obj);	
		return;
	}
	else
	{
		alert("不应该到达此处，说明VC源代码有错误。");
		g_deviceTypeId = -1;
		//g_callBackObjs = null;
	}
	
	cancelProcess();
}
function getAddedDeviceItemObj(g_sn,item,editMethodName)
{
	item = setDoorParams(item);
	var isStartWeek = "";
	var isStartHoliday = "";//alert(JSON.stringify(item));
	if(item.door != undefined)
	{
		if(0x01 & (item.door).dwFlag)
			isStartHoliday = '<span style="color:#7acd53;">'+getLanTextByKey("T_START_SCHEDUAL_TIPS")+'</span>';
		else
			isStartHoliday = "";	
			
		if(0x01 & ((item.door).dwFlag>>1))
			isStartWeek = '<span style="color:#7acd53;">'+getLanTextByKey("T_START_SCHEDUAL_TIPS")+'</span>';
		else
			isStartWeek = "";
	}
	var customBtnNum = 1;
	return [{"index":COL_SELECT,"val":getCheckBoxById(item.nID,"cb_device_","selectedDeviceCallBack")},{"index":COL_NO,"val":g_sn},{"index":COL_NAME,"val":item.szName},{"index":COL_MODEL,"val":item.szType},{"index":COL_IP,"val":item.szIP},{"index":COL_MAC,"val":item.szMAC},{"index":COL_PORT,"val":item.dwPort},{"index":COL_WEEK,"val":isStartWeek},{"index":COL_HOLIDAY,"val":isStartHoliday},{"index":COL_OPERATION,"val":getRowOperateBtns(getLanTextByKey("T_EDIT_DEIVCE_BTN_TIPS"),getLanTextByKey("T_DEL_DEIVCE_BTN_TIPS"),"editAddedDevice","confirmDelDevice",customBtnNum)},{"condition":0,"trBkColor":"","tips":"","obj":item}];				
}
function getDeviceNameById(did)
{
	if(g_aCurrentDeviceData == null)
		return "";
	for(var i = 0; i < g_aCurrentDeviceData.length; i++)
	{
		var item = (g_aCurrentDeviceData[i][g_aCurrentDeviceData[i].length - 1])["obj"];
		if(item.nID == did)
			return item.szName;
	}
	return "";
}
function setDoorParams(item)
{
	if(g_aDoorsWeekData != undefined && g_aDoorsWeekData != null)
	{
		for(var i = 0; i < g_aDoorsWeekData.length; i++)
		{
			if(g_aDoorsWeekData[i].nID == item.nID)
			{
				item.door = g_aDoorsWeekData[i];
			}
		}	
	}
	return item;
}
/*把设备对象转selectUI适用的对象*/
function convertDeviceToComboxData(aDevice)
{
	var aDeviceObj = {"-1":"--"+getLanTextByKey("T_PLS_SELECT_TIPS")+"--"};
	for(var i = 0;i<aDevice.length;i++)
	{
		var item = (aDevice[i][aDevice[i].length - 1])["obj"];
		aDeviceObj[item.nID+""] = item.szName;
	}
	return aDeviceObj;
}
//列出所有已加设备代码（结束）////////////////////////////////////////////////////////////////////////////


//列出所有门（开始）////////////////////////////////////////////////////////////////////////////
var g_aCurrentDoorData = null;
function ListAllDoors(callBackMethod)
{
	if(callBackMethod != undefined)
		g_callBackObjs = callBackMethod;
	startProcess();
	g_sn = 0;
	g_aCurrentDoorData = new Array();

	var ret = _externalListDoor('OnDoorItem');
	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);
	g_callBackObjs = null;
}
//回调函数，每得到一条设备信息被调用一次
function OnDoorItem(szItem)
{
	eval('var item = ' + szItem);
	//item.nCode 错误码。为1时表示列表线程开始，其它成员无效，为2时表示线程结束，其它成员无效，为0时表示一行数据除szMsg成员无效外，其它成员都有效。小于0时表示出错，下面的成员除szMsg外都无效
	//item.szMsg 当出错时该成员才有效，包含错误的文本信息。
	//item.nID 设备在数据库中的ID号
	//item.dwType 设备类型码
	//item.szType 设备类型显示名
	//item.szName 设置名
	//item.szIP 设备IP地址
	//item.dwPort 端口号
	//item.dwReader 读头协议
	//item.szMAC 设备MAC地址
	if (item.nCode == 1)//列表线程已启动
	{
		return;
	}
	else if (item.nCode == 2)
	{
		if(g_callBackObjs != null)
		{
			cancelProcess();
			setTimeout(function(){
			eval(g_callBackObjs);
			g_callBackObjs = null;
			},100);
		}
		
		return;
	}
	else if (item.nCode < 0)
	{
		showToast(item.szMsg,DIALOG_MASK_TIP_MODE,2);//同时也表示操作错误完成
		cancelProcess();
		g_callBackObjs = null;
		return;
	}
	else if (item.nCode == 0)
	{
		//dwMask/*修改项掩码，IDX索引值参考enum DOOR_INDEX*/,
    //nID/*门或设备ID*/,
    //szName/*门名，注意不是设备名*/,
    //dwLockRelay,
    //dwLatchMode/*很重要！开门模式。0表示普通模式。1表示门栓模式。2表示有效认证开门后门在门可开时段内不关闭。3表示门在可开时段内自动打开*/,
    //dwSwitchType/*出门按钮类型。0表示常闭，1表示常开*/,
    //dwSwitchTime,
    //dwSensorType/*门磁类型。0表示常闭，1表示常开，注意：界面上应与门开超时放在一起*/,
    //dwLockDelay/*很重要!门锁延时，取值0至255*/,
    //dwOpenTimeout/*门开超时时长，取值0至50*/,
    //nRdID1/*读头1的ID*/,
    //szRdName1,
    //dwRdAuthMode1/*很重要！读头1的认证模式。修改这个参数必须同时修改下面读头2对应的参数*/,
		g_aCurrentDoorData.push(item);
		return;
	}
	else
	{
		alert("不应该到达此处，说明VC源代码有错误。");
	}
	
	g_callBackObjs = null;
}
//校准设备时间
function correctDeviceTime()
{
	var ret = _externalSetAllDevTime('OnCorrectDeviceItem');
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作
		return 0;
	}
	var oJson = {"mode":LOG_ERROR_TIPS,"msg":replaceStr(err.szMsg,"\n","<br/>")};
	insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);
	removeTabListStopOperationRow();
	g_isCloseCurrentWinMode = true;
	//setTimeout(function(){removePopTabWin();},2000);
}
function OnCorrectDeviceItem(szItem)
{
	var oJson = null;
	eval('var item = ' + szItem);
	//item.nCode 错误码。
	//item.nLevel 级别。0普通提示（黑）1着重提示（蓝）2警告（桔）3错误（红）
	//item.szMsg 当出错时该成员才有效，包含错误的文本信息。
	
	if (item.nCode == 1)//列表线程已启动
	{
		oJson = {"mode":LOG_NORMAL_TIPS,"msg":replaceStr(item.szMsg,"\n","<br/>")};
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);
	}
	else if (item.nCode == 2)
	{
		oJson = {"mode":LOG_SUCCESS_TIPS,"msg":getLanTextByKey("T_COMPLETE_ALL_DEVICE_CORRECT_TIPS")};
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);
		removeTabListStopOperationRow();
		g_isCloseCurrentWinMode = true;
		//setTimeout(function(){removePopTabWin();},2000);
		return;
	}
	else if (item.nCode < 0)
	{
		oJson = {"mode":LOG_ERROR_TIPS,"msg":replaceStr(item.szMsg,"\n","<br/>")};
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);
		g_isCloseCurrentWinMode = true;
		//setTimeout(function(){removePopTabWin();},2000);
		return;
	}
	else if (item.nCode == 0)
	{
		oJson = {"mode":item.nType,"msg":replaceStr(item.szMsg,"\n","<br/>")};
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);
	}
	//else
//		alert("不应该到达此处，说明VC源代码有错误。");
	//alert(szItem);
}
//根据型号获取认证模式
function getCertificateModeByModel(type)
{
	/*
	//D系列控制器范围
	#define ANSON_DMIN   AS_ME_TYPE_DL_24
	#define ANSON_DMAX   0x10310
	//F系列指纹机范围
	#define ANSON_FMIN   0x10260
	#define ANSON_FMAX   0x10280
	
	//DE系列设备范围
	#define ANSON_DEMIN  0x10215
	#define ANSON_DEMAX  0x10310
	#define AS_ME_TYPE_DE_12       0x10222
	#define AS_ME_TYPE_DE_20       0x10245
	#define AS_ME_TYPE_DE_20IC     0x10246
	#define AS_ME_TYPE_DE_20T      0x10247
	#define AS_ME_TYPE_DE_30T      0x10249
	
	#define AS_ME_TYPE_DF_20       0x10260
	#define AS_ME_TYPE_DF_30       0x10262
	#define AS_ME_TYPE_DF_40       0x10264
	//人脸
	#define AS_ME_TYPE_FF_20       0x10281 Face 7M
	#define AS_ME_TYPE_FF_30       0x10282 Face 7L
	#define AS_ME_TYPE_FF_40       0x10283 Face 7
	#define AS_ME_TYPE_FF_50       0x10284 Face 5
	#define AS_ME_TYPE_FF_60       0x10285 Face 5T
	*/
	var g_cerModeObj = null;
	
	if(g_startFaceMode)
		g_cerModeObj = {"-1":"","0":getLanTextByKey("T_OPEN_BY_CARD"),"1":getLanTextByKey("T_OPEN_BY_PWD"),"2":getLanTextByKey("T_OPEN_BY_CARD_OR_PWD"),"3":getLanTextByKey("T_OPEN_BY_CARD_PWD"),"5":getLanTextByKey("T_OPEN_BY_FINGERPRINT"),"6":getLanTextByKey("T_OPEN_BY_FGP_OR_CARD"),"7":getLanTextByKey("T_OPEN_BY_FGP_CARD"),"9":getLanTextByKey("T_OPEN_BY_FGP_OR_PWD"),"10":getLanTextByKey("T_OPEN_BY_FGP_PWD"),"8":getLanTextByKey("T_OPEN_BY_FGP_CARD_PWD"),"13":getLanTextByKey("T_OPEN_BY_FACE"),"11":getLanTextByKey("T_OPEN_BY_FACE_OR_CARD"),"12":getLanTextByKey("T_OPEN_BY_FACE_CARD"),"14":getLanTextByKey("T_OPEN_BY_FGP_OR_PWD_OR_CARD"),"15":getLanTextByKey("T_OPEN_BY_FACE_OR_PWD"),"16":getLanTextByKey("T_OPEN_BY_FACE_PWD"),"17":getLanTextByKey("T_OPEN_BY_FACE_OR_PWD_OR_CARD")};
	else
		g_cerModeObj = {"-1":"","0":getLanTextByKey("T_OPEN_BY_CARD"),"1":getLanTextByKey("T_OPEN_BY_PWD"),"2":getLanTextByKey("T_OPEN_BY_CARD_OR_PWD"),"3":getLanTextByKey("T_OPEN_BY_CARD_PWD"),"5":getLanTextByKey("T_OPEN_BY_FINGERPRINT"),"6":getLanTextByKey("T_OPEN_BY_FGP_OR_CARD"),"7":getLanTextByKey("T_OPEN_BY_FGP_CARD"),"9":getLanTextByKey("T_OPEN_BY_FGP_OR_PWD"),"10":getLanTextByKey("T_OPEN_BY_FGP_PWD"),"8":getLanTextByKey("T_OPEN_BY_FGP_CARD_PWD"),"14":getLanTextByKey("T_OPEN_BY_FGP_OR_PWD_OR_CARD"),"15":getLanTextByKey("T_OPEN_BY_FACE_OR_PWD"),"16":getLanTextByKey("T_OPEN_BY_FACE_PWD"),"17":getLanTextByKey("T_OPEN_BY_FACE_OR_PWD_OR_CARD")};
	var nCerModeObj = {};
	var aModels = [
									{"minType":0x10215,"maxType":0x10259,"cerMode":new Array("-1","0","1","2","3")},/*控制器范围*/
									{"minType":0x10260,"maxType":0x10280,"cerMode":new Array("-1","0","1","2","3","4","5","6","7","9","8","14")},/*指纹机*/
									{"minType":0x10281,"maxType":0x10310,"cerMode":new Array("-1","1","13","11","12","15","16","17")}/*人脸*/
								];	
	for(var i = 0; i < aModels.length; i++)
	{
		if(type >=	aModels[i]["minType"] && type <= aModels[i]["maxType"])
		{
				for(var j = 0; j < (aModels[i]["cerMode"]).length; j++) 
					nCerModeObj[aModels[i]["cerMode"][j]] = g_cerModeObj[aModels[i]["cerMode"][j]];
		}
	}
	return nCerModeObj;
}
/*
	nInType 为1表示输入常开，为0为常闭。 缺省加入的设备默认为1
nOutMode 为0时表示输出与输入同步，为1时表示延时报警。 缺省加入的设备默认为0
nAlarmDelay 表示报警延时。取值0至255（秒）。缺省加入的设备默认为0
	修改设备时在原来的基础上增加了4个参数，如果不加入这4个参数与原来的版本相同。否则加入这4个参数表示要修改报警。
_externalModifyDevice(..., nAlarmMask, nInType, nOutMode, nAlarmDelay),最后的三个参数的含义请参考上面的信息。
nAlarmMask为1时表示修改了nInType, 为2时表示修改了nOutMode,为4时表示修改了nAlarmDelay
	*/
//根据型号获取认证模式
function getAlarmInputMode()
{
	var g_alarmModeObj = {"-1":"","1":getLanTextByKey("T_NORMAL_OPEN"),"0":getLanTextByKey("T_NORMAL_CLOSE")};
	
	return g_alarmModeObj;
}
//根据型号获取认证模式
function getAlarmOutputMode()
{
	var g_alarmModeObj = {"-1":"","0":getLanTextByKey("T_ALARM_INPUT_SYNC_TIPS"),"1":getLanTextByKey("T_ALARM_DELAY_TIPS")};
	
	return g_alarmModeObj;
}
var g_isProductTest = false;
function customBtnCallBackMethodByPara(btn)
{
  if(!g_isProductTest)
  {
    g_dowloadSetup = true;
	 confirmInitDevice(btn);
  }
  else
  {
    g_control = btn;
   initDeviceById(); 
  }
}
function confirmInitDevice(btn)
{
	if(btn.disabled)
		return;
	//setIcoAbtnStatus(btn,true);
	g_control = btn;//getFirstParentObjByTag(btn,"tr");
	var item = (getFirstParentObjByTag(g_control,"tr")).hideContent;	
	var sConfirm = new customConfirm();
	sConfirm.init(getLanTextByKey("T_COMFIRM_INIT_DEVICE_TIPS").replace("%1",'&nbsp;<span style="color:#cd1a1a;">\"' + item.szName + '\"</span>&nbsp;'),"callBackConfirmInitDevice");
}
function callBackConfirmInitDevice(isYes)
{
	if(isYes)
		setTimeout(function(){initDeviceById();	},800);
}
function initDeviceById()
{
	var item = (getFirstParentObjByTag(g_control,"tr")).hideContent;	
	executeInitDeviceById(item.nID);
}
function executeInitDeviceById(did)
{
	startProcess();;
	g_onlyMoveProcTab = true;
	var ret = _externalInitDevice('onInitDevice',parseInt(did,10));
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作
		
		return 0;
	}
	g_onlyMoveProcTab = true;
	cancelProcess(null,4);
	
	setTimeout(function(){showToast(err.szMsg,TOAST_MASK_TIP_MODE,2);},100);
}
function onInitDevice(szRet)
{
	eval('var err = ' + szRet);
	//err.nCode 错误码。大于等于0时表示无错误且为设备的ID号。szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	g_onlyMoveProcTab = true;
	cancelProcess(null,4);
	
	if (err.nCode < 0)
		setTimeout(function(){showToast(err.szMsg,TOAST_MASK_TIP_MODE,2);},100);
	else
	{
		updateDeviceItem(err.nCode);
		setTimeout(function(){showToast(getLanTextByKey("T_COMPLETE_INIT_DEVICE_TIPS"),TOAST_MASK_TIP_MODE,2,new Array(420),"",true);},100);
	}
}
function checkDeviceType(dwType,checkType)
{
	/*
	//D系列控制器范围
	#define ANSON_DMIN   AS_ME_TYPE_DL_24
	#define ANSON_DMAX   0x10310
	//F系列指纹机范围
	#define ANSON_FMIN   0x10260
	#define ANSON_FMAX   0x10280
	
	//DE系列设备范围
	#define ANSON_DEMIN  0x10215
	#define ANSON_DEMAX  0x10310
	#define AS_ME_TYPE_DE_12       0x10222
	#define AS_ME_TYPE_DE_20       0x10245
	#define AS_ME_TYPE_DE_20IC     0x10246
	#define AS_ME_TYPE_DE_20T      0x10247
	#define AS_ME_TYPE_DE_30T      0x10249
	
	#define AS_ME_TYPE_DF_20       0x10260
	#define AS_ME_TYPE_DF_30       0x10262
	#define AS_ME_TYPE_DF_40       0x10264
	//人脸
	#define AS_ME_TYPE_FF_20       0x10281 Face 7M
	#define AS_ME_TYPE_FF_30       0x10282 Face 7L
	#define AS_ME_TYPE_FF_40       0x10283 Face 7
	#define AS_ME_TYPE_FF_50       0x10284 Face 5
	#define AS_ME_TYPE_FF_60       0x10285 Face 5T
	*/	
	var aModels = [
									{"minType":0x10215,"maxType":0x10259,"type":CARD_MODE},/*控制器范围*/
									{"minType":0x10260,"maxType":0x10280,"type":FINGER_MODE},/*指纹机*/
									{"minType":0x10281,"maxType":0x10310,"type":FACE_MODE}/*人脸*/
								];	
	for(var i = 0; i < aModels.length; i++)
	{
		if(aModels[i]["type"] === checkType && dwType >=	aModels[i]["minType"] && dwType <= aModels[i]["maxType"])
			return true;
	}
	return false;
}
var g_advOpts = [];
function ListAdvOpt(callBackMethod)
{
	onListAdvOpt.callBackMethod = callBackMethod;
	var ret = _externalListAdvOpt("onListAdvOpt");	
}
function onListAdvOpt(szRet)
{
	eval('var item = ' + szRet);
	if (item.nCode < 0)
	{
	}
	else if (item.nCode === 0)
	{
		/*
			nCode:0,
			nID:%d,  //设备ID
			nFLMode:%d,//补光灯模式
			nFLTimeSeg:%d,//补光灯定时常开时段
			nFLDelay:%d,//补光灯检测人员经过自动亮起后延时多少秒关闭
			nLEDBrightness:%d,//LED亮度
			nVolume:%d,//音量
			dwMiscMask:%d,//第0位置位表示活体检测开启。第1位置位表示显示黑白小画面。第2位置位表示休眠开启。第8位置位表示事件拍照开启。（注意是第8位，第二个字节的第1位）
			nSleepDelay:%d,//延时休眠时长
			nRcgnThrs:%d//识别阈值
		*/
		g_advOpts.push(item);
	}
	else if (item.nCode === 2)
	{
		if(onListAdvOpt.callBackMethod != "")
		{
			eval(onListAdvOpt.callBackMethod);
		}
		updateTabListForAdvOpts(g_advOpts);
	}
}

var ADVOPT_IDX_FLMODE = 2;//补光模式
var ADVOPT_IDX_FLTIMESEG = 4;//补光常亮开关时段
var ADVOPT_IDX_FLDELAY = 8;//补光打开延时时长
var ADVOPT_IDX_LEDBRIGHTNESS = 0x10;//LED亮度
var ADVOPT_IDX_VOLUME = 0x20;//音量调节
var ADVOPT_IDX_SNAPSHOT = 0x40;//事件抓拍开关
var ADVOPT_IDX_LVING_BODY = 0x80;//活体检测开关
var ADVOPT_IDX_MONO_PIC = 0x100;//黑白小画面开关
var ADVOPT_IDX_SLEEP = 0x200;//休眼开关
var ADVOPT_IDX_SLEEP_DELAY = 0x400;//延时休眠时长
var ADVOPT_IDX_RECN_THRS = 0x800;//识别阈值
var ADVOPT_IDX_EPDC_PRVT = 0x1000;//疫情防范

var ADVOPT_IDX_SNAPSHOT_DWMISCMASK = 8;// 事件抓拍开关
var ADVOPT_IDX_LVING_BODY_DWMISCMASK = 0;// 活体检测开关
var ADVOPT_IDX_MONO_PIC_DWMISCMASK = 1;// 黑白小画面开关
var ADVOPT_IDX_SLEEP_DWMISCMASK = 2;// 休眼开关
function modifyAdvParas(item,isStartUI)
{
	//var dwMask = 0;
	if(isStartUI)
	{
		onModifyAdvParas.isStartUI = isStartUI;
		startProcess(4,null);
	}
	else
		onModifyAdvParas.isStartUI = false;
	
  onModifyAdvParas.bDownload = item.bDownload;
  if(item.isModiTemper)
    onModifyAdvParas.isModiTemper = true;
  console.log(item);
	var ret =_externalModifyAdvOpt('onModifyAdvParas', 
																	item.dwMask/*修改项掩码，IDX索引值参考enum DOOR_INDEX*/,
																	item.nID/*门或设备ID*/,
																	item.nFLMode/*补光灯模式*/,
																	item.nFLTimeSeg/*补光灯定时常开时段*/,
																	item.nFLDelay/*补光灯检测人员经过自动亮起后延时多少秒关闭*/,
																	item.nLEDBrightness/*LED亮度*/,
																	item.nVolume/*音量*/,
																	item.dwMiscMask/*第0位置位表示活体检测开启。第1位置位表示显示黑白小画面。第2位置位表示休眠开启。第8位置位表示事件拍照开启。（注意是第8位，第二个字节的第1位）*/,
																	item.nSleepDelay/*延时休眠时长*/,
																	item.nRcgnThrs/*识别阈值*/,
																	item.bDownload/*表示除了要存入数据库还要立即下载到设备（即立即生效）。*/,
                                  item.dwDPMask,/*体温异常禁止通行(为1时）；体温异常是否触发异常(为1时）；是否开启体温检测(暂未开放，缺省开启）；是否开启必须配戴口罩检测（暂未开放，缺省开启但未实现）*/
                                  item.nHighBT,/*报警最高温*/
                                  item.nLowBT,/*报警最低温*/
                                  item.nBTAdjust/*温度补偿0-14*/
																	);
	
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作
		
		return 0;
	}
	if(isStartUI)
	{
		cancelProcess(null,4);
		showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);
	}
}
//修改设备代码////////////////////////////////////////////////////////////////////////////
function onModifyAdvParas(szRet)
{
	eval('var err = ' + szRet);
	//err.nCode 错误码。大于等于0时表示无错误且为设备的ID号。szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode < 0 && onModifyAdvParas.isStartUI)
		showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);
	else
	{
		//g_control.childNodes[ADDED_DEVICE_TAB_COL_NAME_INDEX].innerText = document.getElementById("txt_device_name").value;
		//(g_control.parentNode).removeChild(g_control.nextSibling);
		var jsons = [];
    err.bDownload = onModifyAdvParas.bDownload;
		jsons.push(err);
		
		isDialogAddDeviceCallBack = true;
    if(onModifyAdvParas.isModiTemper)
    {
      onModifyAdvParas.isModiTemper = false;
      modifyTemperatureCallBackPage(jsons);
    }
    else
		  modifyAdvCallBackPage(jsons);
		g_control = null;
		if(onModifyAdvParas.isStartUI && (!onModifyAdvParas.isModiTemper))
			clearEditTabIdentify(jsons);
	}
	if(onModifyAdvParas.isStartUI)
		cancelProcess(null,4);
}
function rebootAddedDevice(nID)
{
  startProcess(4,null);
  //g_onlyMoveProcTab = true;
  var ret = _externalRebootDevice('onRebootAddedDevice',parseInt(nID,10));
  eval ('var err = ' + ret);
  //err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
  //err.szMsg 当出错时该成员才有效，包含错误的文本信息。
  if (err.nCode >= 0)
  {
    //此处应禁用所有按钮，只允许取消按钮可以操作
    return 0;
  }
  //g_onlyMoveProcTab = true;
  cancelProcess(null,4);
  setTimeout(function(){showToast(err.szMsg,TOAST_MASK_TIP_MODE,2);},100);
}
function onRebootAddedDevice(szRet)
{
	eval('var err = ' + szRet);
	//err.nCode 错误码。大于等于0时表示无错误且为设备的ID号。szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	
	//cancelProcess(null,4);	
	if (err.nCode < 0)
		setTimeout(function(){showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);},100);
	else
		executeRebootDelayTimes(20);//setTimeout(function(){showToast(getLanTextByKey("T_COMPLETE_INIT_DEVICE_TIPS"),TOAST_MASK_TIP_MODE,2,new Array(420),"",true);},100);
}
function executeRebootDelayTimes(s)
{
  setTimeout(function(){cancelProcess(null,4);},s*1000);
}

function adjustBTBase(nID)
{
  var ret = _externalAdjustBTBase('onAdjustBTBase',parseInt(nID,10));
  eval ('var err = ' + ret);
  //err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
  //err.szMsg 当出错时该成员才有效，包含错误的文本信息。
  if (err.nCode >= 0)
  {
    //此处应禁用所有按钮，只允许取消按钮可以操作
    return 0;
  }
  cancelProcess(null,4);
  setTimeout(function(){showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);},100);
}
function onAdjustBTBase(szRet)
{
  g_startProc = true;
	eval('var err = ' + szRet);
	//err.nCode 错误码。大于等于0时表示无错误且为设备的ID号。szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	console.log("szRet = " + szRet);
  console.log(err);
	//cancelProcess(null,4);	
	if (err.nCode < 0)
  {console.log("err.nCode = " + err.nCode)
    var tips = err.szMsg;
   	setTimeout(function(){showToast(tips,DIALOG_MASK_TIP_MODE,2);},100); 
  }	
	else
		executeRebootDelayTimes(1);//setTimeout(function(){showToast(getLanTextByKey("T_COMPLETE_INIT_DEVICE_TIPS"),TOAST_MASK_TIP_MODE,2,new Array(420),"",true);},100);
}