//
var COL_SELECT = 0;
var COL_NO = 1;
var COL_NAME = 2;
var COL_DEPT = 3;
var COL_CODE = 4;
var COL_CARD = 5;
var COL_PWD = 6;
var COL_GENDER = 7;
var COL_GROUP = 8;
var COL_FINGER = 9;
var COL_FACE = 10;
var COL_DATE = 11;
var COL_DOOR = 12
var COL_OPERATE = 13;
var COL_JOB = 14;
var COL_TEL = 15;
var COL_ADDR = 16;

var g_emp_tab_aIndex = new Array(COL_SELECT,COL_NO,COL_NAME,COL_CODE,COL_DEPT,COL_GENDER,COL_GROUP,COL_CARD,COL_PWD,COL_FINGER,COL_FACE,COL_DATE,COL_DOOR,COL_OPERATE);
var g_dept_tab_aIndex = new Array(COL_SELECT,COL_NO,COL_NAME,COL_DATE,COL_OPERATE);
var EMP_CARD_NULL = "";

var g_emp_data_tab_aIndex = new Array(COL_NO,COL_NAME,COL_CODE,COL_DEPT,COL_GENDER,COL_GROUP,COL_CARD,COL_JOB,COL_TEL,COL_ADDR,COL_FACE);

var g_emp_data_tab_styles = [
														{"index":COL_NO,"name":getLanTextByKey("T_SN"),"isDisplay":1,"align":"center","width":40,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":50,"fwidth":35,"id":"","key":"szNumber","default":-1},
														{"index":COL_NAME,"name":getLanTextByKey("T_STAFF_NAME"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":g_cutUserNameStrLen,"fwidth":80,"id":"txt_user_name","key":"szName","default":""},
														{"index":COL_DEPT,"name":getLanTextByKey("T_DEPARTMENT"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":UI_MODE_SELECT,"padding":-1,"isSort":true,"cutStrLen":20,"fwidth":80,"id":"select_dept","key":"nDepartment","default":0},
														{"index":COL_CODE,"name":getLanTextByKey("T_CODE"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":10,"fwidth":60,"id":"txt_code","key":"szCode","default":""},
														{"index":COL_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,"id":"txt_card","key":"szCard","default":""},
														{"index":COL_GENDER,"name":getLanTextByKey("T_GENDER_TITLE"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":UI_MODE_SELECT,"padding":-1,"isSort":true,"cutStrLen":50,"fwidth":40,"id":"select_gender","key":"dwGender","default":0},
														{"index":COL_GROUP,"name":getLanTextByKey("T_EMP_TYPE_TITLE"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":UI_MODE_SELECT,"padding":-1,"isSort":true,"cutStrLen":50,"fwidth":50,"id":"select_emp_type","key":"dwFlag","default":1},
														{"index":COL_JOB,"name":getLanTextByKey("T_EMP_POSITION_TITLE"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":g_cutUserNameStrLen,"fwidth":80,"id":"txt_job_title","key":"szTitle","default":""},
														{"index":COL_TEL,"name":getLanTextByKey("T_EMP_PHONE_TITLE"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":g_cutUserNameStrLen,"fwidth":80,"id":"txt_phone","key":"szTel","default":""},
														{"index":COL_ADDR,"name":getLanTextByKey("T_EMP_ADDRESS_TITLE"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":g_cutUserNameStrLen,"fwidth":80,"id":"txt_address","key":"szAddress","default":""},
														{"index":COL_FACE,"name":getLanTextByKey("T_EMP_FACE_TITLE"),"isDisplay":1,"align":"center","width":140,"noWrap":"nowrap","addBtnMode":VAR_MODE_STRING,"padding":-1,"isSort":true,"cutStrLen":g_cutUserNameStrLen,"fwidth":80,"id":"txt_szphoto","key":"szPhoto","default":""}
											];

var g_emp_tab_styles = [];
var g_dept_tab_styles = [];
var g_cutUserNameStrLen = 20;
var g_aEmpInfos = null;
var g_aDeptInfos = null;
var g_sn = -1;
var maxDeptAmount = 500;

var g_deptObj = null;
var g_photoDir = "";
var g_szName = "";
var g_szCard = "";
var g_nDepartmentID = 0;
var g_aSelectedEmps = [];
var MAX_SELECTEDEMPS_AMOUNT = 200;
var g_isAddingEmpInfo = false;
var MAX_EMPS_AMOUNT = 500;
var MAX_EMPS_CARD_NUMBER = 1099511627775;
var CONNECT_DEVICE_BEYOND_TIME = -108;
function initPhotoDirPath()
{
	g_photoDir = _externalGetPhotoDir();
}
function getDeptByPageIndex()
{
	ListDept(g_pageSize,g_nPage,true,null);	
}
function ListDept(pageSize, nPage,bAscOrderLastUpdate,callBackMethod)
{
	if(callBackMethod != undefined)
		g_callBackObjs = callBackMethod;
	g_aDeptInfos = new Array();
	g_sn = 0;

	startProcess(1,null);

	//(callback, nID, szName, bAscOrderLastUpdate)
	var nID = 0;
	var szName = '';
	var ret = _externalListDepartment('OnHolderDeptItem', pageSize, nPage,bAscOrderLastUpdate);
	eval ('var err = ' + ret);
	if (err.nCode >= 0)
		{
			//此处应禁用所有按钮，只允许取消按钮可以操作
			return 0;
	}
	showToast(err.szMsg,2,2);
	cancelProcess();
	g_callBackObjs = null;
}
//回调函数，每得到一条设备信息被调用一次
function OnHolderDeptItem(szItem)
{
	eval('var item = ' + szItem);
	//item.nCode 错误码。为1时表示列表线程开始，其它成员无效，为2时表示线程结束，其它成员无效，为0时表示一行数据除szMsg成员无效外，其它成员都有效。小于0时表示出错，下面的成员除szMsg外都无效
	
	//item.nID 部门ID
	//item.szName 部门名称
	//item.szModifyTime 
	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;	
		
		if(g_isInitListUI)
		{
			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,"getDeptByPageIndex",g_currentTabListId);	
			}
		}
		return;
	}
	else if (item.nCode == 2)
	{
		setTimeout(function(){cancelProcess();},500);
		if(g_isInitListUI)
		{
			initDeptData(g_aDeptInfos);
			g_aDeptInfos = null;
		}
		else
			g_isInitListUI = true;
		delaySetMask();
		if(checkMethodName(g_callBackObjs))
		{
			setTimeout(function(){eval(g_callBackObjs);	},50);
		}
		g_callBackObjs = null;
		return;
	}
	else if (item.nCode < 0)
	{
		if(item.szMsg != undefined)
			showToast(item.szMsg,2,2);//同时也表示操作错误完成
		else if(g_bDebugMode)
			console.log(item);		
	}
	else if (item.nCode == 0)
	{
		var obj = getDeptItemInfoObj((++g_sn)+((g_nPage-1)*g_pageSize),item);		
		g_aDeptInfos.push(obj);
		return;
	}
	setTimeout(function(){cancelProcess();},500);
	g_callBackObjs = null;
}

function convertArrayObjToJsonObj(aJsons,IdFieldKey,NameFieldKey,defaultSelectTxt)
{
	//g_deptObj = {"-1":"--"+getLanTextByKey("T_PLS_SELECT_TIPS")+"--","2":"市场部","1":"行政","3":"生产部","4":"研发部","5":"销售部","6":"市场部1","7":"行政1","8":"生产部1","9":"研发部1","10":"销售部1","12":"市场部","13":"行政","14":"生产部","15":"研发部","16":"销售部","17":"市场部1","18":"行政1","19":"生产部1","20":"研发部1","21":"销售部1"};
	//delete g_deptObj[1];
	//alert(getObjKeyVal(g_deptObj));
	var obj = {"-1":"--"+defaultSelectTxt+"--"};
	for(var i = 0;i<aJsons.length;i++)
	{
		var len = aJsons[i].length;
		obj[""+aJsons[i][len-1]["obj"][IdFieldKey]] = aJsons[i][len-1]["obj"][NameFieldKey];
	}
	return obj;
}
function getDeptItemInfoObj(sn,item)
{
	var jsons = [{"index":COL_SELECT,"val":getCheckBoxById(item.nID,"cb_dept_","callBackSelectedDept")},{"index":COL_NO,"val":sn},{"index":COL_NAME,"val":item.szName},{"index":COL_DATE,"val":item.szModifyTime},{"index":COL_OPERATE,"val":getRowOperateBtns(getLanTextByKey("T_EDIT_DEPT_BTN_TIPS"),getLanTextByKey("T_DEL_TIPS"),"editDeptItemInfo","confirmDelDept")},{"condition":0,"trBkColor":"","tips":"",obj:item,callbackmethod:null}];	
	
	return jsons;			
}
function confirmDelDept(btn)
{
	if(btn.disabled)
		return;	
	g_control = getFirstParentObjByTag(btn,"tr");
	var item = g_control.hideContent;
	
	btn.disabled = true;
	
	var sConfirm = new customConfirm();
	sConfirm.init(getLanTextByKey("T_DEL_ITDEPT_TIPS").replace("%1",'<span style="color:#cd1a1a;">\"' + item.szName + '\"</span>'),"callBackConfirmDelDept");
	btn.disabled = false;
}
function callBackConfirmDelDept(isDel)
{
	if(isDel)
		delDept(g_control.hideContent);
}
function delDept(item)
{
	//var item = getFirstParentObjByTag(btn,"tr").hideContent;
	var ret =  _externalDelDepartment('onDelDepartment', item.nID);
	eval ('var ret = ' + ret);
	if (ret.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作
		return 0;
	}
	
	showToast(ret,2,2);
	cancelProcess();
}
function onDelDepartment(szItem)
{
	eval('var item = ' + szItem);
	if (item.nCode < 0)
	{
		cancelProcess();
		//showToast(item.szMsg,getLanTextByKey("T_ERROR_TIPS_TITLE"));
		return;
	}
	else if (item.nCode == 1)//列表线程已启动
		return;
	else if (item.nCode >= 0)
	{
		cancelProcess();
		setTimeout(function(){g_isInitListUI = true;getDeptByPageIndex();},200);
		return;
	}
	
}
function editDept(btn)
{
	g_startProc = true;
	g_isInitListUI = true;
	var deptObj = document.getElementById("txt_dept_name");
	if(deptObj == null | deptObj.value == "")
	{
		deptObj.focus();
		return;
	}
	var item = btn.hideContent;
	
	var ret = null;
	if(item == undefined)
	{
		//ret = _externalAddDepartment('onAddDepartment', deptObj.value);
		addDept(deptObj.value)
		return;;
	}
	else
	{
		startProcess(4,null);
		if(item.szName != deptObj.value)
			ret = _externalModifyDepartment('onModifyDepartment', item.nID, deptObj.value);			
		else
		{
			deptObj.focus();
			g_onlyMoveProcTab = true;
			cancelProcess(4,null);
			return;
		}
	}
	eval ('var ret = ' + ret);
	if (ret.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作
		return 0;
	}
	
	showToast(ret,2,2);
	cancelProcess();
}
var g_callBackDetpMethod = null;
function addDept(deptName,callBackMethod)
{
	g_callBackDetpMethod = null;
	
	if(callBackMethod != undefined)
		g_callBackDetpMethod = callBackMethod;
	startProcess(4,null);

	var ret = _externalAddDepartment('onAddDepartment', deptName);

	eval ('var ret = ' + ret);
	if (ret.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作
		return 0;
	}
	if(g_isInitListUI)
		showToast(ret,2,2);
	g_isInitListUI = true;
	cancelProcess();
}
function onAddDepartment(szItem)
{
	eval('var item = ' + szItem);
	if (item.nCode < 0)
	{
		cancelProcess(null,4);
		if(g_isInitListUI)
			showToast(item.szMsg,2,2);
		g_isInitListUI = true;
		return;
	}
	else if (item.nCode == 1)//列表线程已启动
		return;
	else if (item.nCode == 0)
	{
		if(g_isInitListUI)
		{
			setTimeout(function(){removePopTabWin(POP_TAB);g_startProc = false;},20);
			setTimeout(function(){g_isInitListUI = true;ListDept(g_pageSize,g_nPage,true,'resetStartProc();');},500);
		}
		
		if(g_callBackDetpMethod != null)
			g_callBackDetpMethod(item);
		g_startProc = true;
		g_isInitListUI = true;
		return;
	}
}

function resetStartProc()
{
	g_startProc = true;
	cancelProcess(null,4);
}
function onModifyDepartment(szItem)
{
	eval('var item = ' + szItem);
	if (item.nCode < 0)
		showToast(item.szMsg,2,2);
	else if (item.nCode == 0)//列表线程已启动
	{
		//cancelProcess(null,4);
		setTimeout(function(){removePopTabWin(POP_TAB);},20);
		modifyDeptList(item);
		return;
	}
}
//列出所有持有人代码////////////////////////////////////////////////////////////////////////////

//列出持有者
function ListHolder(szCard,szName,pageSize,nPage,nDepartmentID,isAsc,callBackMethod)
{
	//console.log("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
	//console.log(ListHolder.caller);
	//console.log("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");	
	g_aEmpInfos = new Array();
	g_sn = 0;
	g_callBackObjs = null;
	if(callBackMethod != undefined)
		g_callBackObjs = callBackMethod;
	//参数1为szName人员姓名过滤。参数2为szCard卡号过滤。参数3为nRows每页行数。参数4为nPage转到第几页，当nPage为0时表示首页（即0页与第1页相同），小于0时表示尾页。
	
	//console.log(pageSize+", nPage = "+nPage+", "+szName+", "+szCard+", "+nDepartmentID+", "+isAsc);
	
	startProcess(1,null);
	var ret = _externalListEmployee('OnHolderItem', pageSize, nPage, szName, szCard,nDepartmentID,isAsc);//(!g_test)?'OnHolderItem':'OnHolderItem1'
	
	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 OnHolderItem(szItem)
{
	//console.log("-------这里注意list不成功的情况------");
	//console.log(szItem);
	var item;
	eval('item = ' + szItem);
	
	//item.nCode 错误码。为1时表示列表线程开始，其它成员无效，为2时表示线程结束，其它成员无效，为0时表示一行数据除szMsg成员无效外，其它成员都有效。小于0时表示出错，下面的成员除szMsg外都无效
	//item.szMsg 当出错时该成员才有效，包含错误的文本信息。
	//item.nID 人员在数据库中的ID号
	//item.szName 人员姓名
	//item.szCode 人员编号（工号）
	//item.szCard 卡号。卡号字串长度为0时表示该人员未分配卡
	//item.bFingerprint1 0表示指纹1未采集。否则表示已采集
	//item.bFingerprint2 0表示指纹2未采集。否则表示已采集
	//item.bFingerprint3 0表示指纹2未采集。否则表示已采集
	//item.bFace 0表示人脸未采集。否则表示已采集（暂时固定传回0）
	
	//item.nDepartment 部门ID
	//item.szDepartment 部门名称
	
	if (item.nCode == 1)//列表线程已启动
	{
		//此时item结构如下
		//item.nCode 肯定为1
		//item.nPage 当前页页号
		//item.nRows 每页最大显示行数
		//item.nTotalPages 搜索结果总页数	
		
		if(!g_isInitListUI)
		{	
      g_nTotalPage = item.nTotalPages
			return;
		}
		if(g_nTotalPage != item.nTotalPages && g_nTotalPage)
			g_isInitSplitPage = false;		
		if(g_nPage != item.nPage)
			g_isInitSplitPage = false;	
		if(!g_isInitSplitPage)
		{
			g_nTotalPage = item.nTotalPages
			g_nPage = item.nPage;
			g_isInitSplitPage = true;
			initSplitPageTable(document.getElementById("td_tab_list_split"),g_nTotalPage,g_nPage,"getEmpsByPageIndex",g_currentTabListId);	
			//initSplitPageNavBySize(g_nTotalPage,g_nPage,"getEmpsByPageIndex");			
		}
		return;
	}
	else if (item.nCode == 2)
	{
		//deleteRowsToIndexByTab("tab_list",0);	
		if(g_isInitListUI)
		{
			initEmpData(g_aEmpInfos);		
			//g_aEmpInfos = null;
		}
		if(g_callBackObjs != null)
		{
			setTimeout(function(){
					g_callBackObjs(g_aEmpInfos);
				},50);
		}
		setTimeout(function(){cancelProcess();},500);
		return;
	}
	else if (item.nCode < 0)
		showToast(item.szMsg,DIALOG_MASK_TIP_MODE,2);//同时也表示操作错误完成
	else if (item.nCode == 0)
	{
		var obj = getEmpItemInfoObj(++g_sn,item);
		g_aEmpInfos.push(obj);
		return;
	}
	//else
//		alert("不应该到达此处，说明VC源代码有错误。");
	setTimeout(function(){cancelProcess();},500);
}
function getEmpItemInfoObj(g_sn,item)
{
	var sn = (g_nPage - 1) * g_pageSize+g_sn;
	var borderColor = "#55bdf0";
	//console.log("g_nPage="+g_nPage+",,g_sn = "+g_sn+",  sn="+sn);
	var cbObj = getCheckBoxById(item.nID,"cb_emp_","selectedEmpCallBack",borderColor);
	cbObj.value = item.nID;
	cbObj.initCheckedStatus = false;
	if(g_aDoorsWeekData)
	{
		var isSelectedTempStatus = checkEmpIsSelected(g_aSelectedEmps,item);	
		var tObj = getDoorListByMask(g_aDoorsWeekData,item.DoorMask);
		
		if(item.dwFlag & 128)
		{
			borderColor = "#ccc";
			var status = getCheckedStatus(g_aSelectedDoors,item.DoorMask);
			
			status = (!status)?-1:status;
			cbObj = getCheckBoxById(item.nID,"cb_emp_","selectedEmpCallBack",borderColor,-2);	
			cbObj.initCheckedStatus = status;	
			cbObj.tips = getLanTextByKey("T_NO_SET_ADMIN_TITLE");
		}
		//else if((item.DoorMask + "") != "0")
		else if(tObj.isTips)
		{
			var status = getCheckedStatus(g_aSelectedDoors,item.DoorMask);
			status = (!status)?-1:status;
			borderColor = (status < 0)?"#f49d1a":"#55bdf0";
			cbObj = getCheckBoxById(item.nID,"cb_emp_","selectedEmpCallBack",borderColor,(isSelectedTempStatus != -1)?isSelectedTempStatus:status);	
			cbObj.initCheckedStatus = status;				
			cbObj.tips = tObj.tips;//"该人员已被授权门：<br/>会议室门，办公室门，仓库门dwDoorMask="+item.DoorMask;
			cbObj.tipsWidth = tObj.maxLen;
		}
		else
		{
			cbObj = getCheckBoxById(item.nID,"cb_emp_","selectedEmpCallBack",borderColor,(isSelectedTempStatus != -1)?isSelectedTempStatus:false);	
			cbObj.initCheckedStatus = false;
		}
	}
	
	var jsons = [{"index":COL_SELECT,"val":cbObj},{"index":COL_NO,"val":sn},{"index":COL_NAME,"val":item.szName},{"index":COL_DEPT,"val":item.szDepartment},{"index":COL_CODE,"val":item.szCode},{"index":COL_CARD,"val":item.szCard},{"index":COL_PWD,"val":(item.szPwd == "")?"":"******"},{"index":COL_GENDER,"val":((item.dwGender != 0) ? getLanTextByKey("T_FEMALE_TITLE") : getLanTextByKey("T_MALE_TITLE"))},{"index":COL_GROUP,"val":(((item.dwFlag & 128))? getLanTextByKey("T_ADMIN") : getLanTextByKey("T_GENERAL_EMP_TITLE"))},{"index":COL_FINGER,"val":getNumImg(1,item)},{"index":COL_FACE,"val":getListFaceImg(false,FACE_MODE,1,item,false,false)},{"index":COL_DATE,"val":""},{"index":COL_DOOR,"val":""},{"index":COL_OPERATE,"val":getRowOperateBtns(getLanTextByKey("T_EDIT_EMP_BTN_TIPS"),getLanTextByKey("T_DEL_TIPS"),"editEmp","confirmDelEmp")},{"condition":0,"trBkColor":"","tips":"",obj:item,callbackmethod:"rowHoverCallBackEvent"}];	
	return jsons;		//isWithNumber,mode,amount,item,isWithBtn		
}
function checkEmpIsSelected(aSelectedEmps,item)
{
	for(var i = 0; i < aSelectedEmps.length; i++)
	{
		if(aSelectedEmps[i].nID == item.nID)
		{
			return 	aSelectedEmps[i].checked;
		}	
	}
	return -1;
}
function getCheckedStatus(selectedDevices,mask)
{
	var isChecked = false;
	var preIsChecked = -2;
	for(var i = 0; i < selectedDevices.length; i++)
	{
			if((mask >> selectedDevices[i].nID) & 0x01 == 1)
			{
				if(preIsChecked == false)
				{
						isChecked = -1;
						break;
				}
				else 
					isChecked = true;
				preIsChecked = isChecked;
			}
			else
			{
					if(preIsChecked == true)
					{
						isChecked = -1;
						break;
					}
					else 
						isChecked = false;
					preIsChecked = isChecked;
			}	
				
	}
	return isChecked;
}

function getDoorListByMask(doorsWeek,mask)
{
	var obj = new Object();
	obj.tips = '<div style="padding:0.4rem;"><table><tr><td colspan="2">';
	obj.tips += (getLanTextByKey("T_SET_GROUP_DEVICE_TIPS").replace("%1","")) + '</td></tr>';
	var count = 0;
	obj.maxLen = 200;
	obj.isTips = false;
	for(var i = 0; i < doorsWeek.length; i++)
	{
			if((mask >> doorsWeek[i].nID) & 0x01 == 1)
			{
				var dName = (doorsWeek[i].szCtrlName.length>g_maxDeviceNameLength)?cutStringByLen(doorsWeek[i].szCtrlName,g_maxDeviceNameLength):doorsWeek[i].szCtrlName;
				obj.tips += '<tr><td>(' + (++ count) + ') </td><td>' + doorsWeek[i].szCtrlName+'</td>';
				obj.isTips = true; 
				obj.maxLen = (doorsWeek[i].szCtrlName.length > obj.maxLen)?doorsWeek[i].szCtrlName.length:obj.maxLen;
			}
	}	
	obj.tips += "</table></div>";
	obj.maxLen = (obj.maxLen>g_maxDeviceNameLength)?g_maxDeviceNameLength:obj.maxLen;
	obj.maxLen += (obj.maxLen * g_singleCharWidth)+20;
	
	return obj;
}
function getEmpOperateBtns()
{
	var pack = document.createElement("div");
	pack.style.cssText = "width:120px;overflow:hidden;";
	var editBtn = createAbtn("icon_edit icobtn",getLanTextByKey("T_EDIT_EMP_BTN_TIPS"),"editEmp");
	editBtn.style.cssText = "padding-top:7px;width:36px;";
	var delBtn = createAbtn("icon_del delicobtn",getLanTextByKey("T_DEL_TIPS"),"confirmDelEmp");
	delBtn.style.cssText = "padding-top:7px;width:36px;margin-left:6px;";
	var queryPhotoBtn = createAbtn("icon_browser_img icobtn","","confirmDelEmp");
	queryPhotoBtn.style.cssText = "padding-top:7px;width:36px;margin-left:6px;";
	pack.appendChild(editBtn);
	pack.appendChild(delBtn);
	//pack.appendChild(queryPhotoBtn);
	return pack;
}

function getCardPack(item,sn,aTips,mode,idStr,inputMode,callBack)
{
	var cardTab  = document.createElement("table"); 
	//cardTab.style.backgroundColor = "#ccc";
	cardTab.style.margin = "0px";
	cardTab.border = "0";
	cardTab.cellPadding = "0";
	cardTab.cellSpacing = "0";
	//cardTab.width = "380px";
	var cardRow = cardTab.insertRow();
	var cellStyleText = "border:#ccc solid 0px;padding:0px;";
	var cardCell = cardRow.insertCell();	
	cardCell.style.cssText = cellStyleText;
	cardCell.valign = "middle";
	var pack  = document.createElement("div"); 
	var btnSaveCardNo = createAbtn("icon_save icobtn",aTips[1],(mode == INPUT_TYPE_NUM)?"addEmpCardNumber":"addEmpPwd");//new Object();
	btnSaveCardNo.mode = mode;
	
	if(item == undefined | item == null)
	{
		btnSaveCardNo.cid = "txt_number";
		btnSaveCardNo.sn = sn;
		btnSaveCardNo.hideContent = item;
		btnSaveCardNo.cid = "txt_number";
	}
	else
	{
		btnSaveCardNo.cid = "txt_number_"+((item.nID == undefined)?0:item.nID);
		btnSaveCardNo.sn = sn;
		btnSaveCardNo.hideContent = item;
		btnSaveCardNo.cid = "txt_number_"+((item.nID == undefined)?0:item.nID);		
	}
	btnSaveCardNo.id = idStr.replace("txt","btn_save");
	btnSaveCardNo.style.cssText = "margin-left:6px;";
	setEasyUITooltips(btnSaveCardNo,'top',200,1);	//设置tips
	setIcoAbtnStatus(btnSaveCardNo,true);
	var tips = getAddInfoDeviceBtnTipsByMode(CARD_MODE);		
	var obj = getLanTextKeyByMode(CARD_MODE);
	var nTips = tips["skey"];
	var selecteDeviceInfo = (GetStore(obj["saveKey"],true));
	var aSelectedDeviceInfo = null;
	if(selecteDeviceInfo != undefined && selecteDeviceInfo != null && selecteDeviceInfo != "")
	{
		aSelectedDeviceInfo = selecteDeviceInfo.split(g_saveToLocalSplitChar);
		var deviceName = getDeviceNameById(parseInt(aSelectedDeviceInfo[0],10));
		aSelectedDeviceInfo[1] = ((aSelectedDeviceInfo[1] == undefined | aSelectedDeviceInfo[1] == "" | aSelectedDeviceInfo[1] == null)?"":aSelectedDeviceInfo[1]);
		aSelectedDeviceInfo[1] = (deviceName == "")?aSelectedDeviceInfo[1]:deviceName;
		aSelectedDeviceInfo[1] = (aSelectedDeviceInfo[1] =="")?"":("<br/>" + getLanTextByKey("T_CUR_DEFAULT_SELECTED_DEVICE_TIPS") +" "+ aSelectedDeviceInfo[1]);
		nTips = (aSelectedDeviceInfo[1] =="")?tips["skey"]:tips["mkey"] + aSelectedDeviceInfo[1];
	}		
	
	var btnAddCardNo = createAbtn("icon_add_card icobtn",((aTips.length<3)?aTips[1]:aTips[2]),"SetCardByDevice");
	btnAddCardNo.style.cssText = "margin-left:6px;";
	btnAddCardNo.id = idStr.replace("txt","btn_add");
	
	btnAddCardNo.cid = idStr;
	btnAddCardNo.btnid = "btn_modify_add_card_devices_list";
	btnAddCardNo.hideContent = item;
	
	setEasyUITooltips(btnAddCardNo,'top',200);	//设置tips
	
	var intputCard = null;	
	if(inputMode != undefined)
	{
		if(callBack != undefined && callBack != "")
			intputCard = getEditInput(idStr,aTips[0],30,inputMode,callBack);
		else
			intputCard = getEditInput(idStr,aTips[0],30,inputMode);
	}
	else
		intputCard = getEditInput(idStr,aTips[0]);	
	intputCard.style.cssText = "width:200px;";
	intputCard.type = (mode == INPUT_TYPE_NUM)?"text":"password";
	intputCard.hideContent = item;
	intputCard.mode = "input";
	if(item != undefined && item != null)
	{
		intputCard.value = (mode == INPUT_TYPE_PWD)?item.szPwd:item.szCard;
		intputCard.initVal = intputCard.value;
	}
	cardCell.appendChild(intputCard);
	pack.appendChild(btnSaveCardNo);
	if(mode == INPUT_TYPE_NUM)
	{
		pack.appendChild(btnAddCardNo);	
		var btnModifyDevice = createAbtn("icon_device_list icobtn",nTips,"modifyDeviceList");
		btnModifyDevice.style.cssText = "margin-left:6px;";
		btnModifyDevice.hideContent = item;
		btnModifyDevice.mode = CARD_MODE;
		btnModifyDevice.id = btnAddCardNo.btnid;
		btnAddCardNo.btnid = btnAddCardNo.btnid;
		btnModifyDevice.did = (aSelectedDeviceInfo == null)?-1:aSelectedDeviceInfo[0];	
		pack.appendChild(btnModifyDevice);
	}
	cardCell = cardRow.insertCell();
	cardCell.style.cssText = cellStyleText;
	cardCell.valign = "middle";
	cardCell.appendChild(pack);	
	return cardTab;
}
function getNumImg(mode,item)
{
	var numDiv  = document.createElement("div"); 
	var num = 0;
	if(item.bFingerprint1)
		num++;
	if(item.bFingerprint2)
		num++;
	if(item.bFingerprint3)
		num++;
	
	var spFinger  = document.createElement("span"); 
	spFinger.className = "icon_finger";
	spFinger.style.cssText = "font-size:2rem;color:#"+((num > 0)?"78cd51":"ccc")+";";	
	var spFont  = document.createElement("span"); 
	spFont.style.cssText = "margin-left:2px;font-size:1.2rem;color:#"+((num > 0)?"78cd51":"ccc")+";";	
	spFont.innerText = num;
	
	numDiv.appendChild(spFont);
	numDiv.appendChild(spFinger);
	return numDiv;
}
function getListFaceImg(isWithNumber,mode,amount,item,isWithBtn,isBtn)
{
	var spFace  = document.createElement("span"); 	
	spFace.className = "icon_face";
	spFace.style.color = "#"+((item.bFace)?"78cd51":"858585");
	spFace.style.fontSize = "2rem";
	spFace.id = "list_face_"+item.nID;
	return spFace;
}
function getNoImg(isWithNumber,mode,amount,item,isWithBtn,isBtn)
{
	var tab  = document.createElement("table"); 
	//tab.className = "tab_list";
	tab.style.margin = "0px";
	tab.border = "0";	
	tab.cellPadding = "0";
	tab.cellSpacing = "0";
	var row = tab.insertRow();
	var cellStyleText = "border:#55bdf0 solid 0px;padding:1px;";
	var numLetfInitPos =  -61;
	var numTopInitPos =  -297;
	var numWidth = 14;
	var isClick  = (isBtn == undefined | !isBtn)?false:true;
	var aFinger = null;
	if(item != null)
		aFinger = (mode == 1)?new Array(((item.bFingerprint1)?1:0),((item.bFingerprint2)?1:0),((item.bFingerprint3)?1:0)):null;
	var isHasEmpInfo = false;
	for(var i = 0; i < amount; i++)
	{
		var isSelected = false;
		if(mode == FINGER_MODE & item != null)
		{
			isSelected = (aFinger[i])?true:false;
		}
		else if(mode == FACE_MODE & item != null)
		{
			isSelected = (item.bFace)?true:false;
		}
		else
			isSelected = false;
		if(isSelected)
			isHasEmpInfo = true;
		var cell1 = row.insertCell();	
		cell1.style.cssText = cellStyleText;
		cell1.vAlign = "middle";
		var idIdentfyStr = (mode == FINGER_MODE)?"finger":"face";
		cell1.id = idIdentfyStr + "_btn_"+i;
		var color = "#"+((isSelected)?"78cd51":"858585");
		
		cell1.number = i;
		if(isBtn)
		{
			var numDiv  = document.createElement("a"); 
			numDiv.innerText = i + 1;
			cell1.isSelected = isSelected;
			numDiv.id = "div_num_"+idIdentfyStr+"_"+i;			
			numDiv.style.cssText = "float:left;width:24px;height:24px;margin-left:2px;padding-top:"+((lan == "en")?3:0)+"px;margin-right:10px;border-radius:50%;color:#fff;text-align:center;background-color:"+ color +";";//-283 
		
			cell1.cid = numDiv.id;
			cell1.mode = mode;
			if(mode == FACE_MODE)
				cell1.fmode = FACE_MODE;
			cell1.btnid = "btn_num_"+idIdentfyStr;
			cell1.className = "btn_td_imge";
			cell1.onclick = function(){addEmpCertificateInfo(this);};
		}
		cell1.mode = (mode == FINGER_MODE)?FINGER_MODE:FACE_MODE;
		
		var cell = row.insertCell();	
		cell.style.cssText = cellStyleText;
		
		var imgDiv  = document.createElement(((isClick)?"a":"span")); 
		
		imgDiv.id = "div_img_"+idIdentfyStr+"_"+i;
		var aClassName = (isSelected)?"icoselectedbtn":"icounselectedbtn";
		var iconFinger = "icon_add_emp_finger "+aClassName;//(item == null)?"icon_add_emp_finger":"icon_finger";
		imgDiv.className = ((mode == FINGER_MODE)?iconFinger:"icon_face "+aClassName);
		imgDiv.style.cssText = "float:left;margin-left:2px;padding:0px;background-color:transparent;font-size:2em;";//color:"+bkColor+";
		if(!isClick)
			imgDiv.style.color = color;
		imgDiv.mode = mode;
	
		cell1.isSelected = isSelected;
		
		cell1.hideContent = item;
		
		var tips = getAddInfoDeviceBtnTipsByMode(mode);
		var obj = getLanTextKeyByMode(mode);
		var nTips = tips["skey"];
		
		cell.vAlign = "middle";
		var aSelectedDeviceInfo = null;
		var selecteDeviceInfo = (GetStore(obj["saveKey"],true));
		
		if(selecteDeviceInfo != undefined && selecteDeviceInfo != null && selecteDeviceInfo != "")
		{			
			aSelectedDeviceInfo = selecteDeviceInfo.split(g_saveToLocalSplitChar);
			cell1.did = aSelectedDeviceInfo[0];
			var deviceName = getDeviceNameById(parseInt(aSelectedDeviceInfo[0],10));
			aSelectedDeviceInfo[1] = (deviceName == "")?aSelectedDeviceInfo[1]:deviceName;
		}
		if(isClick)
		{
			var cTips = tips[(!isSelected)?"ntips":"mtips"];
			//imgDiv.tips = (amount > 1)?cTips.replace("%1",i+1):cTips;
			if(amount > 1)
			{
				var cnum = i+1;
				var ennum = "";
				switch(cnum)
				{
					case 1:
						ennum = cnum + "st";
						break;	
					case 2:
						ennum = cnum + "nd";
						break;
					case 3:
						ennum = cnum + "rd";
						break;
				}
				
				var rnum = (lan == "en")?ennum:cnum;
				imgDiv.tips = cTips.replace("%1",rnum);
				
			}
			else
				imgDiv.tips = cTips;
			setEasyUITooltips(imgDiv);
			var nColor = (isSelected)?"#78cd51":"#00ccff";
			imgDiv.initNColor = nColor;
			imgDiv.onmouseover = function(){this.style.color = "#368fca";};
			imgDiv.onmouseout = function(){this.style.color = this.initNColor;};
		}
		cell1.appendChild(imgDiv);
		if(amount > 1)
			cell.appendChild(numDiv);
		
		if(i == amount -1 && isWithBtn)
		{
			cell = row.insertCell();	
			cell.style.cssText = cellStyleText;
			cell.valign = "middle";
			if(mode == FACE_MODE && g_isDynamicFace)
			{
				var fTips = getLanTextByKey("T_ADD_FACE_BY_PHOTO_TIPS");
				if(item != undefined && item != null)
				{
					fTips = getLanTextByKey((item.bFace)?"T_MODIFY_FACE_BY_PHOTO_TIPS":"T_ADD_FACE_BY_PHOTO_TIPS");
					fTips = fTips.replace("%1","<br/>");
					fTips = fTips.replace("%1","<br/>");
				}
				var btnAddFaceByPhoto = createAbtn("icon_photo icobtn",fTips,"CollectFaceByPhoto");
				btnAddFaceByPhoto.style.cssText = "margin-left:10px;";
				btnAddFaceByPhoto.hideContent = item;
				btnAddFaceByPhoto.id = "btn_add_face_photo";
				btnAddFaceByPhoto.btnid = "btn_num_"+idIdentfyStr;
				btnAddFaceByPhoto.fmode = 2;
				btnAddFaceByPhoto.mode = FACE_MODE;
				var fColor = "#"+((isSelected)?"78cd51":"00ccff");
				btnAddFaceByPhoto.style.backgroundColor = fColor;
				btnAddFaceByPhoto.onmouseover = function(){this.style.backgroundColor = "#368fca";};
				btnAddFaceByPhoto.onmouseout = function(){this.style.backgroundColor = fColor;};
				cell.appendChild(btnAddFaceByPhoto);
			}
			var btnDelAtt = createAbtn("icon_del delicobtn",getLanTextByKey((mode == FINGER_MODE)?"T_DEL_ALL_FINGER_DATA_TIPS":"T_DEL_FACE_DATA_TIPS"),(mode == FINGER_MODE)?"confirmDelFinger":"confirmDelFace");
			btnDelAtt.style.cssText = "margin-left:10px;";
			btnDelAtt.hideContent = item;
			btnDelAtt.id = "btn_del_all_"+idIdentfyStr;
			cell.appendChild(btnDelAtt);
			if(!isHasEmpInfo)
				setIcoDelBtnStatus(btnDelAtt,true);
			if(selecteDeviceInfo != undefined && selecteDeviceInfo != null && selecteDeviceInfo != "")
			{	
				if(aSelectedDeviceInfo != -1)
				{
					aSelectedDeviceInfo[1] = ((aSelectedDeviceInfo[1] == undefined | aSelectedDeviceInfo[1] == "" | aSelectedDeviceInfo[1] == null)?"":aSelectedDeviceInfo[1]);
					aSelectedDeviceInfo[1] = (aSelectedDeviceInfo[1] =="")?"":"<br/>" +getLanTextByKey("T_CUR_DEFAULT_SELECTED_DEVICE_TIPS") +" "+ aSelectedDeviceInfo[1];
					nTips = (aSelectedDeviceInfo[1] =="")?tips["skey"]:tips["mkey"] + aSelectedDeviceInfo[1];
				}
			}
			var btnModifyDevice = createAbtn("icon_device_list icobtn",nTips,"modifyDeviceList");
			btnModifyDevice.style.cssText = "margin-left:6px;";
			btnModifyDevice.hideContent = item;
			btnModifyDevice.mode = (mode == FINGER_MODE)?mode:FACE_MODE;
			if(aSelectedDeviceInfo != undefined && aSelectedDeviceInfo != null)
			{
				btnModifyDevice.did = aSelectedDeviceInfo[0];
			}
			if(isBtn)
			{
				btnModifyDevice.id = cell1.btnid;
			}
			cell.appendChild(btnModifyDevice);
		}
	}
	return tab;
}
function getLanTextKeyByMode(mode)
{
	var obj = new Object();
	switch(mode)
	{
		case CARD_MODE:
			obj.key = "T_ADD_CARD_DEVICE_TITLE";	
			obj.saveKey = CARD_DEVICE_PARA_KEY;
			obj.data = g_aAsAddInfoDevice;
			break;
		case FINGER_MODE:
			obj.key = "T_FINGER_DEVICE_TITLE";	
			obj.saveKey = FINGER_DEVICE_PARA_KEY;
			obj.data = g_aFingerAddInfoDevice;
			break;
		case FACE_MODE:
			obj.key = "T_FACE_DEVICE_TITLE";	
			obj.saveKey = FACE_DEVICE_PARA_KEY;
			obj.data = g_aFaceAddInfoDevice;
			break;
	}
	obj.data = (obj.data != null)?convertArrayObjToJsonObj(obj.data,"nID","szName",getLanTextByKey("T_PLS_SELECT_TIPS")):null;
	return obj;
}
function getAddInfoDeviceBtnTipsByMode(mode)
{
	var FINGER_DEVICE_PARA_KEY = "FingerPrint";
	var CARD_DEVICE_PARA_KEY = "CardDevice";
	var jsons = [{"mode":CARD_MODE,"tkey":"T_ADD_CARD_DEVICE_TITLE","key":CARD_DEVICE_PARA_KEY,"skey":getLanTextByKey("T_SELECT_ADD_CARD_DEVICE_LIST_TIPS"),"mkey":getLanTextByKey("T_MODIFY_CUR_ADD_CARD_DEVICE_LIST_TIPS"),"ntips":"","mtips":""},
								{"mode":FINGER_MODE,"tkey":"T_FINGER_DEVICE_TITLE","key":FINGER_DEVICE_PARA_KEY,"skey":getLanTextByKey("T_SELECT_FINGER_DEVICE_LIST_TIPS"),"mkey":getLanTextByKey("T_MODIFY_CUR_FINGER_DEVICE_LIST_TIPS"),"ntips":getLanTextByKey("T_ADD_FINGER_INFO_TIPS"),"mtips":getLanTextByKey("T_MODIFY_FINGER_INFO_TIPS")},
								{"mode":FACE_MODE,"tkey":"T_FACE_DEVICE_TITLE","key":FACE_DEVICE_PARA_KEY,"skey":getLanTextByKey("T_SELECT_FACE_DEVICE_LIST_TIPS"),"mkey":getLanTextByKey("T_MODIFY_CUR_FACE_DEVICE_LIST_TIPS"),"ntips":getLanTextByKey("T_ADD_FACE_INFO_TIPS"),"mtips":getLanTextByKey("T_MODIFY_FACE_INFO_TIPS")}];
	for(var i = 0; i < jsons.length; i++)
	{
		if(jsons[i]["mode"] == mode)
			return 	jsons[i];
	}
}
var g_fingerBtn = null;
function addEmpCertificateInfo(btn)
{	
	g_fingerBtn = btn;
	var obj = document.getElementById(btn.btnid);
	
	if(obj == undefined)
	{
		if(btn.mode == FINGER_MODE)
		{
			isDirectAddFingerByDevice = true;
			modifyDeviceList(document.getElementById("btn_num_finger"));
		}
		else if(btn.mode == FACE_MODE)
		{
			isDirectAddFaceByDevice = true;
			modifyDeviceList(document.getElementById("btn_num_face"));
		}
		
		return;
	}
	if(obj.did == undefined | obj.did == "-1" | obj.did == -1)
	{
		if(btn.mode == FINGER_MODE)
		{
			isDirectAddFingerByDevice = true;
			modifyDeviceList(document.getElementById("btn_num_finger"));
		}
		else if(btn.mode == FACE_MODE)
		{
			isDirectAddFaceByDevice = true;
			modifyDeviceList(document.getElementById("btn_num_face"));
		}
		return;
	}
	startStatusListWin(1000,560);
	if(btn.mode == FINGER_MODE)
		CollectFPByDevice(btn.hideContent,obj.did,btn.number);
	else if(btn.mode == FACE_MODE)
		CollectFAByDevice(btn.hideContent,obj.did,btn.number);
}
//用设备加人脸
function CollectFAByDevice(item,addInfoDevice,index)
{
	g_isHasCallbackError = false;
	closeSelectWin();
	item.index = index;
	item.deviceMode = FACE_MODE;
	item.mode = EMP_DEL_FACE_PHOTO_MODE;//EMP_FINGER_MODIFY_MODE	
	g_item = item;
	var ret = _externalCollectFaceByDevice('OnCollectFAByDevice', item.nID/*人员ID*/, item.szName/*人员姓名，将传入系统日志*/,  parseInt(addInfoDevice,10)/*此处应填入正确的人脸机ID号*/);
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		var oJson  = {"mode":LOG_NORMAL_TIPS,"msg":getLanTextByKey("START_GET_FACE_DESC")};	
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);	
		return 0;
	}
	insertStatusTabItem(STATUS_LIST_DEFAULT_ID,{"mode":LOG_ERROR_TIPS,"msg":err.szMsg});
	g_item = null;
}
function OnCollectFAByDevice(szRet)
{
	eval('var err = ' + szRet);
	//err.nCode 错误码。大于等于0时表示无错误且为设备的ID号。szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode < 0)
	{
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,{"mode":LOG_ERROR_TIPS,"msg":err.szMsg});
		g_isHasCallbackError = true;
	}
	else
	{//item.nLevel 级别。0普通提示（黑）1着重提示（蓝）2警告（桔）3错误（红）
		var oJson = {"mode":LOG_NORMAL_TIPS,"msg":getLanTextByKey("SUCCESS_GET_FACE_DESC")};
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);	
		modifyEmpInfoRelateUI(g_item,err);		
	}	
  displayWinCloseIcon(true,STATUS_POP_WIN_DEFAULT_ID);
	if(!g_isHasCallbackError)
		setTimeout(function(){removeControlById(STATUS_POP_WIN_DEFAULT_ID);delaySetMask();},STATUS_WIN_CLOSE_WATIT_TIME);
	g_item = null;
	g_isHasCallbackError = false;	
	return;
}
var g_path = "";
function CollectFaceByPhoto(btn)
{
	if(btn.disabled)
		return;
	btn.disabled = true;
	g_fingerBtn = btn;
	var obj = document.getElementById(btn.btnid);
	if(obj.did == undefined | obj.did == "-1" | obj.did == -1)
	{		
		isDirectAddFaceByPhotoAndDevice = true;
		btn.disabled = false;
		modifyDeviceList(document.getElementById("btn_num_face"));
		return;
	}
	var path = "";
	if(g_path == "")
	{
		path = getUploadPhotoPath(1);
		g_path = path;
	}
	else 
		path = g_path;
	
	if(path == null)
	{
		g_path = "";
		btn.disabled = false;
		return;
	}
	
	
	if(obj == undefined)
	{
		isDirectAddFaceByPhotoAndDevice = true;
		modifyDeviceList(document.getElementById("btn_num_face"));
		return;
	}
	g_path = "";
	var item = btn.hideContent;
	g_isInitListUI = true;
	g_isToastTips = true;
	setupCollectFaceByPhoto(item,obj.did,path,btn);
}
function CollectFaceByImportPhoto(btn)
{
	if(btn.disabled)
		return;
	btn.disabled = true;
	g_fingerBtn = btn;
	var obj = document.getElementById(btn.btnid);
	if(obj.did == undefined | obj.did == "-1" | obj.did == -1)
	{		
		isDirectAddFaceByPhotoAndDevice = true;
		btn.disabled = false;
		modifyDeviceList(document.getElementById("btn_num_face"));
		return;
	}
	var path = "";
	if(g_path == "")
	{
		path = getUploadPhotoPath(1);
		g_path = path;
	}
	else 
		path = g_path;
	
	if(path == null)
	{
		g_path = "";
		return;
	}
	
	
	if(obj == undefined)
	{
		isDirectAddFaceByPhotoAndDevice = true;
		modifyDeviceList(document.getElementById("btn_num_face"));
		return;
	}
	g_path = "";
	var item = btn.hideContent;
	
	setupCollectFaceByPhoto(item,obj.did,path,btn);
}
var g_AddFacePhotoBtn = null;
var g_callBackFaceMehod = null;
var g_FaceDeviceErrorCode = 0;
var g_isToastTipsCopy = g_isToastTips;
function setupCollectFaceByPhoto(item,dwDevID,szPhoto,btn,callBackMethod,errorCallBackMethod)
{
	//console.log("setupCollectFaceByPhoto(\r\n1. "+item+",\r\n2."+dwDevID+",\r\n3."+szPhoto+",\r\n4."+btn+",\r\n5."+callBackMethod+")");
	g_FaceDeviceErrorCode = 0;
	g_callBackFaceMehod = null;
	g_AddFacePhotoBtn = null;
	item.deviceMode = FACE_MODE;
	item.mode = EMP_FACE_MODIFY_MODE;
	item.dwMask = -1;
	item.newSzPhoto = szPhoto;
	item.modifyPhoto = true;
	g_item = item;
	if(btn != undefined && btn != null)
		g_AddFacePhotoBtn = btn;
	
	if(callBackMethod != undefined)
		g_callBackFaceMehod = callBackMethod;

	if(errorCallBackMethod != undefined)
		OnCollectFaceByPhoto.errorCallBackMethod = errorCallBackMethod;
	
	g_isToastTipsCopy = g_isToastTips;
	//var imgUrl = convertUrlToFileUrl(g_item.newSzPhoto);
	//cutPhoto(encodeFileOrDirNameURI(imgUrl));
	//console.log(' _externalCollectFaceByPhoto("OnCollectFaceByPhoto", '+item.nID+'/*人员ID*/," '+item.szName+'"/*人员姓名*/, '+dwDevID+'/*设备ID*/,"'+szPhoto+'"/*照片的全路径名，请参考人员增加修改照片*/);');
	OnCollectFaceByPhoto.szName = item.szName;
	OnCollectFaceByPhoto.szPhoto = szPhoto;
	
	var ret = _externalCollectFaceByPhoto("OnCollectFaceByPhoto", item.nID/*人员ID*/, item.szName/*人员姓名*/, dwDevID/*设备ID*/, szPhoto/*照片的全路径名，请参考人员增加修改照片*/);
	
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作
		startProcess(4, null);
		return 0;
	}
	else
	{
		if(checkMethodName("recycleAddEmpFaceFailCallBackFunction") && g_isRecycleAddEmpFace)
			setTimeout(function(){recycleAddEmpFaceFailCallBackFunction(err);},0);	
		else if(checkMethodName("recycleAddEmpFaceFailCallBackFunction") && g_isOnlyAddEmpFace)
			setTimeout(function(){recycleAddEmpFaceFailCallBackFunction(err);},0);	
	}
	
	if(g_isToastTips)
		showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);
	cancelProcess(null, 4);
	g_item = null;
	if(g_AddFacePhotoBtn != null)
		g_AddFacePhotoBtn.disabled = false;
	
}
function OnCollectFaceByPhoto(szRet)
{
	eval('var err = ' + szRet);
	//err.nCode 错误码。大于等于0时表示无错误且为设备的ID号。szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	
	if (err.nCode < 0)
	{
    if(err.nCode === NOT_OPEN_FILE)
      err.szMsg = (getLanTextByKey("T_ERR_NOT_OPEN_PHOTO")).replace("%1","<span style='color:blue'>"+g_item.newSzPhoto+"</span>");
		g_FaceDeviceErrorCode = err.nCode;
		var mRes = checkMethodName("recycleAddEmpFaceFailCallBackFunction");
		//if(g_callBackFaceMehod != null)
		//	g_callBackFaceMehod(g_item,err);
		if(g_isToastTipsCopy)
			showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);
		var isExecRecycleAddEmpFaceFailCallBackFunction = false;
		if(g_AddFacePhotoBtn != null)
			g_AddFacePhotoBtn.disabled = false;
		else if(mRes)// && g_isOnlyAddEmpFace)
		{
			isExecRecycleAddEmpFaceFailCallBackFunction = true;
			err.szName = OnCollectFaceByPhoto.szName;
			err.szPhoto = OnCollectFaceByPhoto.szPhoto;
			setTimeout(function(){recycleAddEmpFaceFailCallBackFunction(err);},5);	
		}
		if(OnCollectFaceByPhoto.errorCallBackMethod != undefined && OnCollectFaceByPhoto.errorCallBackMethod != null)
			setTimeout(function(){eval(OnCollectFaceByPhoto.errorCallBackMethod);OnCollectFaceByPhoto.errorCallBackMethod = null;},150);
		if(g_callBackFaceMehod != null && g_addEmpAndFaceAndPhotoMode === 2)
		{
			if(!isExecRecycleAddEmpFaceFailCallBackFunction)
			g_callBackFaceMehod(g_item,err);
		}
		setTimeout(function(){cancelProcess(null, 4);},10);
	}
	else
	{
		g_startProc = false;
		if(g_item != null && g_item.newSzPhoto != "" && g_isInitListUI)
			setFacePhotoToEmpInfo(g_item.newSzPhoto,false,g_item,err);
		if(g_AddFacePhotoBtn != null)
			g_AddFacePhotoBtn.disabled = false;
		g_isInitListUI = true;
		
		if(g_callBackFaceMehod != null)
		{
			g_callBackFaceMehod(g_item,err);
		}
	}
}
//删除人脸代码 开始////////////////////////////////////////////////////////////////////////////
function confirmDelFace(btn)
{
	if(btn.disabled)
		return;
	
	g_control = btn;
	var item = g_control.hideContent;	
	//if(!item.bFace)	
	//	return;
	var sConfirm = new customConfirm();
	btn.disabled = true;
	var tips = getLanTextByKey("T_DEL_FACE_TIPS").replace("%1",'<span style="color:#cd1a1a;">\"' + item.szName + '\"</span>');
	
	sConfirm.init(tips,"callBackConfirmDelFace",CONFIRM_DIALOG_MASK_TIP_MODE);
	btn.disabled = false;
}
function callBackConfirmDelFace(isDel)
{
	if(isDel)
	{
		g_delEmpFaceCallBackMethod = null;
		g_isInitListUI = true;
		DelFace(g_control);
	}
}
function DelFace(btn)
{	
	//if(!confirm(getLanTextByKey("T_DEL_ITEM_TIPS")))
	//	return;
	g_item = null;
	var index = -1;//删除三枚指纹
	var item = btn.hideContent;
	item.mode = EMP_DEL_FACE_MODE;
	item.dwMask = -1;
	item.index = index;
	g_item = item;
	//console.log("item.nID="+item.nID+", item.szName="+item.szName);
	var ret = _externalDelFace('OnDelFace', item.nID/*人员ID*/, item.szName/*人员姓名，将传入系统日志*/);
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作
		startProcess(4, null);
		return 0;
	}
	if(g_isToastTips)
		showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);
	cancelProcess(null, 4);
}
var g_delEmpFaceCallBackMethod = null;
function OnDelFace(szRet)
{
	eval('var err = ' + szRet);
	//err.nCode 错误码。大于等于0时表示无错误且为设备的ID号。szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	var oJson = null;
	if (err.nCode < 0)
	{
		if(g_isToastTips)
			showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);
	}
	else
	{
		g_onlyMoveProcTab = true;
		cancelProcess(null, 4);
		if(g_isToastTips)
			setTimeout(function(){showToast(getLanTextByKey("SUCCESS_DEL_FACE_DESC"),DIALOG_MASK_TIP_MODE,2);delaySetMask();	},1000);
		if(g_isInitListUI)
			modifyEmpInfoRelateUI(g_item);
		else
		{
			delEmpFaceRelateInfo(g_item);
		}
	}
	if(g_delEmpFaceCallBackMethod != null)
			setTimeout(function(){eval(g_delEmpFaceCallBackMethod);},500);
	g_item = null;
}
////删除人脸代码 开始///////////////////////////////
var g_imgUrl = "images/default.jpg";
function getImageBtns(id,browsertips,deltips,szPhoto,item)
{
	var rand = "?id="+Math.round(Math.random()*10000);
	var imgUrl = g_imgUrl;
	var div = document.createElement("div");
	if(szPhoto != "")
	{
		imgUrl = encodeFileOrDirNameURI(convertUrlToFileUrl(szPhoto));
		div.style.backgroundSize = "110px 122px";
	}
	var isCerFace = (item != null && item.szInfo1 == "1");
	div.style.cssText = "width:110px;height:122px;border:#1e8fc6 solid 1px;overflow:hidden;background:url("+imgUrl+rand+") 0px 0px no-repeat;cursor:pointer;text-align:center;padding-top:"+((isCerFace)?0:8)+"px;background-size:110px 122px;";
	//div.appendChild(img);
	div.id = id;
	div.value = szPhoto;
	div.initVal = szPhoto;
	div.mode = "photo";
	div.browsertips = browsertips;
	div.deltips = deltips;
	div.onmouseenter = function(){operateImageBtns(this,true);};
	div.onmouseleave = function(){operateImageBtns(this,false);};
	if(item != null && item.szInfo1 == "1")
	{
		var tDiv= document.createElement("div");
		tDiv.id = "photo_tips"+item.nID;
		tDiv.className = "icon_photo";
		tDiv.style.cssText = "background-color:#78cd51;color:#fff;width:20px;height:20px;padding:1px;font-szie:10px;";
		div.appendChild(tDiv);
	}
	
	return div;
}
function operateImageBtns(obj,isOver)
{
	var uploadId = "div_upload_btn";
	var delId = "div_del_photo_btn";
	var bkColor = "#00ccff";//00ccff
	var btnColor = "#fff";//00ccff
	var sp = document.getElementById(uploadId);	
	var del = document.getElementById(delId);	
	if(isOver)
	{
		if(sp != null)
			return;
		sp = document.createElement("div");
		sp.id = uploadId;
		sp.className = "normalbtn icon_browser_img";
		sp.style.cssText = "font-size:2.6em;color:"+btnColor+";width:110px;height:44px;background-color:"+bkColor+";opacity:0.9;";
		sp.tips = obj.browsertips;
		sp.onclick = function (){uploadPhoto(this,true);};
		setEasyUITooltips(sp,"top",200,0.8);
		obj.appendChild(sp);
		del = document.createElement("div");
		del.id = delId;
		del.className = "normalbtn icon_del";
		del.style.cssText = "font-size:2.6em;color:"+btnColor+";width:110px;height:44px;background-color:"+bkColor+";opacity:0.9;margin-top:16px;";
		del.tips = obj.deltips;
		del.onclick = function (){uploadPhoto(this,false);};
		setEasyUITooltips(del,"top",200,0.8);
		obj.appendChild(del);
	}
	else
	{
		hideEasyUITooltips(sp);
		hideEasyUITooltips(del);
		if(sp != undefined && sp != null &&sp.parentNode != null)
			(sp.parentNode).removeChild(sp);
		if(del != undefined && del != null &&del.parentNode != null)
			(del.parentNode).removeChild(del);
	}
}
function uploadPhoto(obj,isUpload)
{
	var div = document.getElementById("img_photo");
	var imgUrl = "images/default.jpg?id="+Math.round(Math.random()*10000);
	if(isUpload)
	{
		/*var ret = _externalSelectFile("All Supported Formats(*.jpg;*.bmp;*.gif;*.png)|"
												+ "*.JPG;*.BMP;*.GIF;*.PNG;|"
												+ "JPEG Files(*.jpg)|*.JPG|"
												+ "Bitmap Files(*.bmp)|*.BMP|"
												+ "GIF Files(*.gif)|*.GIF|"
												+ "Portable Network Graphic Files(*.png)|*.PNG|",getLanTextByKey("T_PLS_SELECT_PHOTO_TIPS"));		*/
		var ret = getUploadPhotoPath(-1);
		setEmpPhotoUIByUpload(ret);
		/*div.value = ret;
		if(ret != "" && ret != null)
		{
			imgUrl = convertUrlToFileUrl(ret);
			div.style.backgroundSize = "110px 122px";
			div.style.cssText = "width:110px;height:122px;border:#1e8fc6 solid 1px;overflow:hidden;background:url("+encodeFileOrDirNameURI(imgUrl)+") 0px 0px no-repeat;cursor:pointer;text-align:center;padding-top:8px;background-size:110px 122px; ";
		}
		else
			div.value = "";*/
	}
	else
	{
		div.value = "";
		div.style.cssText = "width:110px;height:122px;border:#1e8fc6 solid 1px;overflow:hidden;background:url("+imgUrl+") 0px 0px no-repeat;cursor:pointer;text-align:center;padding-top:8px;background-size:110px 122px; ";
		//list_face_
		var nodes = div.childNodes;
		for(var i = 0; i < nodes.length; i++)
		{
			if((nodes[i].id).indexOf("photo_tips") > -1)
				div.removeChild(nodes[i]);	
		}
	}
	baseEmpInfoCallBack("img_photo");
}
function setEmpPhotoUIByUpload(url)
{
	var div = document.getElementById("img_photo");
	var cNodes = div.childNodes;
	for(var i = 0; i < cNodes.length; i++)
	{
		if((cNodes[i].id).indexOf("photo_tips") > -1)
			 div.removeChild(cNodes[i]);
	}
	div.value = url;
	if(url != "" && url != null)
	{
		imgUrl = convertUrlToFileUrl(url);
		imgUrl = encodeFileOrDirNameURI(imgUrl);
		div.style.backgroundSize = "110px 122px";
		div.style.cssText = "width:110px;height:122px;border:#1e8fc6 solid 1px;overflow:hidden;background:url('"+ imgUrl +"') 0px 0px no-repeat;cursor:pointer;text-align:center;padding-top:8px;background-size:110px 122px; ";
		
	}
	else
		div.value = "";
}
function getUploadPhotoPath(mode)
{
	var photoFormat = {
												"jpg":{"format":"*.jpg","desc":"JPEG Files(*.jpg)|*.JPG"},
												"bmp":{"format":"*.bmp","desc":"Bitmap Files(*.bmp)|*.BMP"},
												"gif":{"format":"*.gif","desc":"GIF Files(*.gif)|*.GIF"},
												"png":{"format":"*.png","desc":"Portable Network Graphic Files(*.png)|*.PNG"}};
	var vStr = "";
	var ret = "";
	if(mode == -1)
	{
		/*ret = _externalSelectFile("All Supported Formats(*.jpg;*.bmp;*.gif;*.png)|"
													+ "*.JPG;*.BMP;*.GIF;*.PNG;|"
													+ "JPEG Files(*.jpg)|*.JPG|"
													+ "Bitmap Files(*.bmp)|*.BMP|"
													+ "GIF Files(*.gif)|*.GIF|"
													+ "Portable Network Graphic Files(*.png)|*.PNG|",getLanTextByKey("T_PLS_SELECT_PHOTO_TIPS"));	*/
		vStr = "All Supported Formats(*.jpg;*.bmp;*.gif;*.png)|"
													+ "*.JPG;*.BMP;*.GIF;*.PNG;|"
													+ "JPEG Files(*.jpg)|*.JPG|"
													+ "Bitmap Files(*.bmp)|*.BMP|"
													+ "GIF Files(*.gif)|*.GIF|"
													+ "Portable Network Graphic Files(*.png)|*.PNG|";
	}
	else if(mode == 1)
	{
		vStr = "All Supported Formats("+photoFormat["jpg"]["format"]+")|"
													+ photoFormat["jpg"]["format"]+";|"
													+photoFormat["jpg"]["desc"]+ "|";
	}
	ret = getSelectFilePath(vStr,getLanTextByKey("T_PLS_SELECT_PHOTO_TIPS"));	
	return ret;
}
//对路径所的文件夹名和文件名进行转码
function encodeFileOrDirNameURI(imgUrl)
{
	var aImgUrl = imgUrl.split("|/");
	var aChildImgUrl = aImgUrl[1].split("/");
	var nImgUrl = aImgUrl[0] + "|";
	for(var i = 0; i < aChildImgUrl.length; i++)
		nImgUrl += "/" + encodeURI(aChildImgUrl[i]);
	return nImgUrl;
}
//路径转化为本地路径
function convertUrlToFileUrl(url)
{
	var aUrls = 	url.split("\\");
	var url = "";
	for(var i = 0; i < aUrls.length; i++)
	{
		if(i == 0)
			url += "file:///"+aUrls[i].replace(":","")+"|";
		else
			url += "/" + aUrls[i];
	}
	return url;
}
var g_isRecycleAddEmp = false;
var g_isRecycleAddEmpFace = false;
function AddEmployee(item,errorCallBackMethod)
{
	var isAdmin = (parseInt(item.dwFlag,10) === 1)?128:0;
	item.dwFlag = isAdmin;
	//alert(JSON.stringify(item));
	//为了简化代码，使用固定字串做为参数。
	startProcess(4,null);
	
	//console.log("item.szName="+item.szName+", item.szCode="+item.szCode+",item.dwGender/*0表男性，1表女性*/="+item.dwGender+", item.szPwd/*密码要么不设，要么是6位数字*/="+item.szPwd+",isAdmin/*0表普通人员。128表示管理员*/="+isAdmin+",item.nDepartment="+item.nDepartment+", item.szPhoto="+item.szPhoto+", item.szBirthday="+ item.szBirthday+", item.szTitle="+item.szTitle+", item.szTel="+item.szTel+", item.szAddress="+item.szAddress);
	if(item != null)
	{
		if(item.szCard === undefined | item.szCard === "" | item.szCard === null)	
			item.szCard = "-1";
	}
	else
		return;
	if(errorCallBackMethod == undefined)
		onAddEmployee.errorCallBackMethod = null;
	else
		onAddEmployee.errorCallBackMethod = errorCallBackMethod;
	
	if(item.szInfo1 == undefined)
		item.szInfo1 = "";
	else if(item.szInfo1 == null)
		item.szInfo1 = "";
	
	if(item.szCard == undefined)
		item.szCard = "";
	else if(item.szCard == null)
		item.szCard = "";
	g_item = item;
	var ret =_externalAddEmployee('onAddEmployee', item.szName, item.szCode,item.dwGender/*0表男性，1表女性*/, item.szPwd/*密码要么不设，要么是6位数字*/,item.dwFlag/*0表普通人员。128表示管理员*/,item.nDepartment, item.szPhoto, item.szBirthday, item.szTitle, item.szTel, item.szAddress, item.szCard,item.szInfo1);
	
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作
		return 0;
	}
	g_isRecycleAddEmp = false;
	
	cancelProcess(null,4);
	setTimeout(function(){showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);},1000);
}
function onAddEmployee(szRet)
{
	eval('var err = ' + szRet);
	//err.nCode 错误码。大于等于0时表示无错误且为设备的ID号。szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	//err.nID 人员在数据库中的ID号
	//err.szName 人员姓名
	//err.szCode 人员编号（工号）
	//err.dwGender 性别。0表示男，1表示女
	//err.szPwd 密码
	//err.dwFlag 属性标志。其中第7位置位表示为管理员。设置时应使用 (err.dwFlag | 128)，清除时应使用(err.dwFlag & ~128)
	
	//err.nDepartment 部门ID
	//err.szDepartment 部门名称
	//err.szBirthday 生日
	//err.szTitle 职位
	//err.szEducation 教育程度
	//err.szTel 电话
	//err.szAddress 家庭住址
	//err.szRemark 备注
	//err.szPhoto 照片
	//err.szCard 卡号
	//err.szExpiryTime 超期时间
	//err.szInfo1 附加信息1
	//err.szInfo2 附加信息2
	//err.szInfo3 附加信息3
	//err.szInfo4 附加信息4
	if (err.nCode < 0)
	{
		cancelProcess(null,4);
		var nRes = checkMethodName("recycleAddEmpFailCallBackFunction");		
		if(checkMethodName("recycleAddEmpFailCallBackFunction") && g_isRecycleAddEmp)
		{
			g_nPage = 1;	
			setTimeout(function(){recycleAddEmpFailCallBackFunction(err);},1);	
		}
		else if(checkMethodName("recycleAddEmpFaceFailCallBackFunction") && g_isRecycleAddEmpFace)
		{
			g_nPage = 1;
			setTimeout(function(){recycleAddEmpFaceFailCallBackFunction(err);},1);	
		}
		else if(g_isInitListUI)
			setTimeout(function(){showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);},100);
		if(onAddEmployee.errorCallBackMethod != undefined && onAddEmployee.errorCallBackMethod != null)
			setTimeout(function(){eval(onAddEmployee.errorCallBackMethod); onAddEmployee.errorCallBackMethod = null;},5);		
	}
	else
	{
		cancelProcess(null,4);
		if((!g_isRecycleAddEmp) && (!g_isRecycleAddEmpFace))
		{
			setTimeout(function(){
				g_onlyMoveProcTab = true;
				g_isInitListUI = true;
				ListHolder(g_szCard,g_szName,g_pageSize,g_nPage,g_nDepartmentID,true);
				},g_msDelayFuncExecute);
		}
		if(g_item.szPhoto != undefined)
			err.initSzPhoto = g_item.szPhoto;
		if(checkMethodName("addEmpSuccessCallBackFunction") && (!g_isRecycleAddEmp))
		{
			g_nPage = 1;
			setTimeout(function(){addEmpSuccessCallBackFunction(err);},5);	
		}
		if(checkMethodName("recycleAddEmpSuccessCallBackFunction") && g_isRecycleAddEmp)
		{
			g_nPage = 1;recycleAddEmpSuccessCallBackFunction(err);	
		}
		else if(checkMethodName("recycleAddEmpFaceSuccessCallBackFunction") && g_isRecycleAddEmpFace)
		{
			g_nPage = 1;setTimeout(function(){recycleAddEmpFaceSuccessCallBackFunction(err);},5);
		}
		return;
	}	
	
}
//删除人员代码////////////////////////////////////////////////////////////////////////////
function confirmDelEmp(btn)
{
	if(btn.disabled)
		return;	
	g_control = getFirstParentObjByTag(btn,"tr");
	var item = g_control.hideContent;	
	btn.disabled = true;	
	var sConfirm = new customConfirm();
	sConfirm.init(getLanTextByKey("T_DEL_ITEM_TIPS").replace("%1",'<span style="color:#cd1a1a;">\"' + item.szName + '\"</span>'),"callBackConfirmDelEmp");
	btn.disabled = false;
}
function callBackConfirmDelEmp(isDel)
{
	if(isDel)
	{
		g_delEmpCallBackMethod = null;
		g_isInitListUI = true;
		delEmp(g_control.hideContent);
	}
}
function delEmp(item)
{
	startProcess();  
	var ret = _externalDelEmployee('onDelEmployee',  item.nID);
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作		
		return 0;
	}
	if(g_isToastTips)
		showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);
	cancelProcess();
}
var g_delEmpCallBackMethod = null;
function onDelEmployee(szRet)
{
	eval('var err = ' + szRet);
	//err.nCode 错误码。大于等于0时表示无错误且为设备的ID号。szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	cancelProcess(szRet);
	if (err.nCode < 0)
	{
		if(g_isToastTips)
			showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);
	}
	else
	{
		if(g_isInitListUI)
			setTimeout(function(){ListHolder(g_szCard,g_szName,g_pageSize,g_nPage,g_nDepartmentID,true);},g_msDelayFuncExecute);
		if(g_delEmpCallBackMethod != null)
			setTimeout(function(){eval(g_delEmpCallBackMethod);},500);
	}
	g_isInitListUI = true;
}
//人员成员修改掩码。注意：未修改成员时一定不要设置，尤其是管理员，因为可能会导致额外的设置下载。
var EMPL_MSK_NAME = (1 << 1);
var EMPL_MSK_EMPLOYEE_NUM = (1 << 2);
var EMPL_IDX_DEPARTMENT = (1 << 3);
var EMPL_MSK_GENDER = (1 << 4);
var EMPL_IDX_BIRTHDAY = (1 << 5);
var EMPL_IDX_JOB_TITLE = (1 << 6);
var EMPL_IDX_TEL = (1 << 8);
var EMPL_IDX_ADDRESS = (1 << 9);
var EMPL_MSK_ADMIN = (1 << 11);
var EMPL_IDX_CARD = (1 << 12);
var EMPL_MSK_PWD = (1 << 13);
var EMPL_IDX_PHOTO = (1 << 22);
var EMP_MODIFY_MODE = 1;
var EMP_CARD_MODIFY_MODE = 2;
var EMP_PWD_MODIFY_MODE = 3;
var EMP_FINGER_MODIFY_MODE = 4;
var EMP_DEL_FINGER_MODE = 5;
var EMP_FACE_MODIFY_MODE = 6;
var EMP_DEL_FACE_MODE = 7;
var EMP_DEL_FACE_PHOTO_MODE = 8;
var EMPL_IDX_ADDTIONAL_INFO1 = (1 << 18);//附加信息1
//EMPL_IDX_ADDTIONAL_INFO2,//附加信息2
//EMPL_IDX_ADDTIONAL_INFO3,//附加信息3
//EMPL_IDX_ADDTIONAL_INFO4,//附加信息4
function checkEmpInfoModify(initItem,item,initDwMask)
{
	var dwMask = 0;
	if(initDwMask != undefined)
		dwMask = initDwMask;
	item.nID = initItem.nID;
	//item.mode = (item.mode != undefined)?item.mode:EMP_MODIFY_MODE;
	item.mmode = (item.mmode != undefined)?item.mmode:EMP_MODIFY_MODE;
	
	item.modifyPhoto = false;
	
	if(item.szName != undefined)
	{
		if (initItem.szName != item.szName)
			dwMask |= EMPL_MSK_NAME;//修改了人员名称加上本行代码
		else
			item.szName = initItem.szName;
	}
	else
		item.szName = initItem.szName;
	
	var dwFlag = initItem.dwFlag;
	if(item.dwFlag != undefined)
	{
		var temmpDwFlag = 0;
		if((item.dwFlag+"") == "1")
			temmpDwFlag |= 128;//设定为管理员。如果设定为普通人员应该是 dwFlag &= ~128;必须如此实现，因为其它位还有其它用途
		else
			temmpDwFlag &= ~128;
		if(temmpDwFlag != dwFlag)
		{
			dwFlag = temmpDwFlag;
			dwMask |= EMPL_MSK_ADMIN;//
		}
	}
	else
		dwFlag = initItem.dwFlag;	
	//if(g_bDebugMode)console.log("item.dwFlag: "+item.dwFlag+ ",, " + dwFlag+" != "+initItem.dwFlag);
	if (dwFlag != initItem.dwFlag)
		dwMask |= EMPL_MSK_ADMIN;//修改了是否为管理员加上本行代码
	else
		dwFlag = initItem.dwFlag;
	//以下省略比较，在实际使用是一定要进行比较
	if(item.szCode != undefined)
	{//if(g_bDebugMode)console.log("szCode: "+initItem.szCode+" != "+item.szCode);
		if (initItem.szCode != item.szCode)
			dwMask |= EMPL_MSK_EMPLOYEE_NUM;//修改了人员工号加上本行代码
		else
			item.szCode = initItem.szCode;
	}
	else
		item.szCode = initItem.szCode;
	
	if(item.nDepartment != undefined)
	{	//if(g_bDebugMode)console.log("nDepartment: "+initItem.nDepartment+" != "+item.nDepartment);
		initItem.nDepartment = (initItem.nDepartment == -1)?0:initItem.nDepartment;		
		if (initItem.nDepartment != item.nDepartment)
			dwMask |= EMPL_IDX_DEPARTMENT;//修改了人员部门加上本行代码
		else
			item.nDepartment = initItem.nDepartment;
	}
	else
		item.nDepartment = initItem.nDepartment;
	
	if(item.dwGender != undefined)
	{//if(g_bDebugMode)console.log("dwGender: "+initItem.dwGender+" != "+item.dwGender);
		if((initItem.dwGender+"") == (item.dwGender+""))
		{
			item.dwGender = initItem.dwGender;
		}
		else if(initItem.dwGender != item.dwGender)
		{
			dwMask |= EMPL_MSK_GENDER;//修改了性别加上本行代码
		}
		else
			item.dwGender = initItem.dwGender;
	}
	else
		item.dwGender = initItem.dwGender;
	
	if(item.szBirthday != undefined)
	{	
		if (initItem.szBirthday != item.szBirthday)
			dwMask |= EMPL_IDX_BIRTHDAY;//修改了生日加上本行代码
		else
			item.szBirthday = initItem.szBirthday;
	}
	else
		item.szBirthday = initItem.szBirthday;
	
	if(item.szTitle != undefined)
	{		//if(g_bDebugMode)console.log("szTitle: "+initItem.szTitle+" != "+item.szTitle);
		if (initItem.szTitle != item.szTitle)
			dwMask |= EMPL_IDX_JOB_TITLE;//修改了工作加上本行代码
		else
			item.szTitle = initItem.szTitle;
	}
	else
		item.szTitle = initItem.szTitle;
	
	if(item.szTel != undefined)
	{//if(g_bDebugMode)console.log("szTel: "+initItem.szTel+" != "+item.szTel);		
		if (initItem.szTel != item.szTel && (item.szTel != "" | initItem.szTel != ""))
			dwMask |= EMPL_IDX_TEL;//修改了电话加上本行代码
		else
			item.szTel = initItem.szTel;
	}
	else
		item.szTel = initItem.szTel;
	
	if(item.szAddress != undefined)
	{	//if(g_bDebugMode)console.log("szAddress: "+initItem.szAddress+" != "+item.szAddress);		
		if (initItem.szAddress != item.szAddress)
			dwMask |= EMPL_IDX_ADDRESS;//修改了地址加上本行代码
		else
			item.szAddress = initItem.szAddress;
	}
	else
		item.szAddress = initItem.szAddress;
	
	if(item.szCard != undefined)
	{	//if(g_bDebugMode)console.log("szCard: "+initItem.szCard+" != "+item.szCard);		
		item.mode = EMP_CARD_MODIFY_MODE;
		if (initItem.szCard != item.szCard)
			dwMask |= EMPL_IDX_CARD;//修改了卡号加上本行代码
		else
			item.szCard = initItem.szCard;
	}
	else
		item.szCard = initItem.szCard;
	
	if(item.szPwd != undefined)
	{//if(g_bDebugMode)console.log("szPwd: "+initItem.szPwd+" != "+item.szPwd);		
		item.mode = EMP_PWD_MODIFY_MODE;	
		if (initItem.szPwd != item.szPwd)
			dwMask |= EMPL_MSK_PWD;//修改了密码加上本行代码
		else
			item.szPwd = initItem.szPwd;
	}
	else
		item.szPwd = initItem.szPwd;
	
	if(item.szPhoto != undefined)
	{	//if(g_bDebugMode)console.log("szPhoto: "+initItem.szPhoto+" != "+item.szPhoto);		
		if(initItem.szPhoto == "" && item.szPhoto != "")
		{
			item.modifyPhoto = true;
			dwMask |= EMPL_IDX_PHOTO;//修改了照片加上本行代码
		}
		else if (item.szPhoto.indexOf(initItem.szPhoto) < 0)
		{
			item.modifyPhoto = true;
			dwMask |= EMPL_IDX_PHOTO;//修改了照片加上本行代码
			if(item.szPhoto == "")
			{
				item.szInfo1 = -1;
				initItem.szInfo1 = "";
			}
		}
		else
			item.szPhoto = initItem.szPhoto;
	}
	else
		item.szPhoto = initItem.szPhoto;
	//if(g_bDebugMode)console.log("szInfo1: "+initItem.szInfo1+" != "+item.szInfo1);		
	if(item.szInfo1 != undefined)
	{
		item.mode = EMP_PWD_MODIFY_MODE;	
		if (initItem.szInfo1 != item.szInfo1)
			dwMask |= EMPL_IDX_ADDTIONAL_INFO1;//修改了密码加上本行代码
		else
			item.szInfo1 = initItem.szInfo1;
	}
	else
		item.szInfo1 = initItem.szInfo1;
	
	//if(g_bDebugMode)console.log("dwMask = "+dwMask);		
	if(!dwMask)
	{
		return null;
	}
	item.dwMask = dwMask;
	item.dwFlag = dwFlag;
	return item;
}
var g_mItem = null;
function ModifyEmployee(btn,item,initDwMask,callBack,gItem)
{
	var initItem = btn.hideContent;	
	item = (initDwMask != undefined && initDwMask != 0)?checkEmpInfoModify(initItem,item,initDwMask):checkEmpInfoModify(initItem,item);
	if(item == null)
	{
		startProcess(4,null);
		return;
	}
	g_mItem = null;
	g_mItem = Object.assign({}, item);//item;
	
	if(callBack != null && callBack != "")
		g_mItem.func = callBack;
	if(gItem != null && gItem != "")
		g_mItem.para = gItem;
	startProcess(4,null);
	var ret = _externalModifyEmployee('onModifyEmployee',item.dwMask, initItem.nID,item.szName, item.szCode, item.dwGender/*0表男性，1表女性*/, item.szPwd/*密码要么为空白，要么是6位数字*/,((callBack == FindNextFile)?item.dwFlagCopy:item.dwFlag), 
																		item.nDepartment,item.szBirthday,item.szTitle, /*在这之前的参数原样传入*/initItem.szEducation, item.szTel,item.szAddress, initItem.szRemark,
																		item.szPhoto, item.szCard, initItem.szExpiryTime, initItem.szInfo1, initItem.szInfo2, initItem.szInfo3, initItem.szInfo4
																		);
	
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作
		return 0;
	}
	cancelProcess(null,4);
	setTimeout(function(){showToast(replaceStr(err.szMsg,"\n","<br/>"),DIALOG_MASK_TIP_MODE,2);},300);
	g_mItem = null;
	
}
function onModifyEmployee(szRet)
{
	g_startProc = true;
	eval('var err = ' + szRet);
	//err.nCode 错误码。大于等于0时表示无错误且为设备的ID号。szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode < 0)
		setTimeout(function(){showToast(replaceStr(err.szMsg,"\n","<br/>"),DIALOG_MASK_TIP_MODE,2);},300);
	else
	{
		if(g_mItem.dwMask)
		{
			modifyUpdateEditWin(g_mItem,err);
			modifyEmpList(g_mItem,err);
		}
		setTimeout(function(){delayExecuteModifyEmployeeGlobalMethod(g_mItem);},1000);
	}	
	cancelProcess(null,4);
	setTimeout(function(){g_mItem = null;},1050);
}
function delayExecuteModifyEmployeeGlobalMethod(mItem)
{
	if(mItem.func != undefined  && mItem.func != null)
	{
		if(mItem.para != undefined)
			(mItem.func)(mItem.para);
		else
			(mItem.func)();
	}	
}

//设备采集指纹代码////////////////////////////////////////////////////////////////////////////
function CollectFPByDevice(item,addInfoDevice,index)
{
	g_isHasCallbackError = false;
	closeSelectWin();
	item.index = index;
	item.deviceMode = FINGER_MODE;
	item.mode = EMP_FINGER_MODIFY_MODE;
	if( parseInt(addInfoDevice,10) == USB_ADD_EMP_INFO_DEVICE_ID)
	{
		CollectFPByCollector(item,parseInt(addInfoDevice,10),index);
		return;
	}
	g_item = item;
	var ret = _externalCollectFPByDevice('OnCollectFPByDevice', item.nID/*人员ID*/, parseInt(index,10)/*第几号指纹0~2*/, item.szName/*人员姓名，将传入系统日志*/, parseInt(addInfoDevice,10)/*此处应填入正确的指纹机ID号*/);
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		var oJson  = {"mode":LOG_NORMAL_TIPS,"msg":getLanTextByKey("START_GET_ATTENDANCE_DESC")};	
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);	
		oJson = {"mode":LOG_IMPORTANT_TIPS,"msg":getLanTextByKey("PLS_INPUT_RIGHT_ATTENDANCE_DESC")};		
		setTimeout(function(){insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);},1000);
		return 0;
	}
	insertStatusTabItem(STATUS_LIST_DEFAULT_ID,{"mode":LOG_ERROR_TIPS,"msg":err.szMsg});
	g_item = null;
	displayWinCloseIcon(true,STATUS_POP_WIN_DEFAULT_ID);
}
function OnCollectFPByDevice(szRet)
{
	eval('var err = ' + szRet);
	//err.nCode 错误码。大于等于0时表示无错误且为设备的ID号。szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode < 0)
	{
		g_isHasCallbackError = true;
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,{"mode":LOG_ERROR_TIPS,"msg":err.szMsg});
	}
	else
	{//item.nLevel 级别。0普通提示（黑）1着重提示（蓝）2警告（桔）3错误（红）
		var oJson = {"mode":LOG_NORMAL_TIPS,"msg":getLanTextByKey("USB_ATTENDANCE_DEVICE_FINISH_DESC")};
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);	
		modifyEmpInfoRelateUI(g_item,err);
	}
  displayWinCloseIcon(true,STATUS_POP_WIN_DEFAULT_ID);
	if(!g_isHasCallbackError)
		setTimeout(function(){removeControlById(STATUS_POP_WIN_DEFAULT_ID);delaySetMask();},STATUS_WIN_CLOSE_WATIT_TIME);

	g_item = null;
	return;
}
//设备设置人员卡号代码////////////////////////////////////////////////////////////////////////////
function SetCardByDevice(btn)
{
	g_isHasCallbackError = false;
	closeSelectWin();
	if(g_isAddingEmpInfo)
		return;
	var item = btn.hideContent;
	var mBtn = (document.getElementById(btn.btnid));
	item.deviceId = mBtn.did;
	g_btn = btn;
	if(item.deviceId == undefined | item.deviceId == "-1" | item.deviceId == -1)
	{
		modifyDeviceList(mBtn);
		isDirectAddCardByDevice = true;
		return;
	}
	item.deviceMode = CARD_MODE;
	item.mode = EMP_CARD_MODIFY_MODE;
	item.editCardId = "txt_card_number";
	g_item = item;
	
	if( parseInt(item.deviceId,10) == USB_ADD_EMP_INFO_DEVICE_ID)
	{
		var otherStopBtn = -2;//USB加卡退出模式不用与软件交互
		startStatusListWin(1000,560,STATUS_LIST_DEFAULT_ID,STATUS_POP_WIN_DEFAULT_ID,TABLE_STATUS_LIST_MODE,otherStopBtn,"closeUSBaddCardWinCallMethod();");//cw,ch,idStr,popWinId,mode,customExitMode
		usbAddCard(btn);
		return;
	}
	else
	{	startStatusListWin(1000,560);}
	//console.log("开启加设备前传递参数：人员ID="+item.nID+",设备ID="+item.deviceId);
	g_isAddingEmpInfo = true;
	var ret = _externalSetCardByDevice('OnSetCardByDevice', item.nID/*人员ID*/, parseInt(item.deviceId,10)/*此处应填入正确的设备ID号*/);
	eval ('var err = ' + ret);
	//console.log("立即返回："+ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作		
		var oJson = {"mode":LOG_NORMAL_TIPS,"msg":getLanTextByKey("AS_START_GET_CARD_NUMBER_DESC")};	
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);	
		oJson = {"mode":LOG_IMPORTANT_TIPS,"msg":getLanTextByKey("AS_GET_CARD_NUMBER_DESC")};
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);
		return 0;
	}
	insertStatusTabItem(STATUS_LIST_DEFAULT_ID,{"mode":LOG_ERROR_TIPS,"msg":err.szMsg});
	g_item = null;
	g_isAddingEmpInfo = false;
	displayWinCloseIcon(true,STATUS_POP_WIN_DEFAULT_ID);	
	//cancelProcess("closeDeviceSelect");
	//g_control = null;
}
function OnSetCardByDevice(szRet)
{
	eval('var err = ' + szRet);
	//err.nCode 错误码。大于等于0时表示无错误且为设备的ID号。szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	//err.szCard 获取到的卡号
	if (err.nCode < 0)
	{
		g_isHasCallbackError = true;
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,{"mode":LOG_ERROR_TIPS,"msg":err.szMsg});
		g_item = null;
		g_isAddingEmpInfo = false;
	}
	else
	{
		var card = err.szCard;
		var oJson = {"mode":LOG_NORMAL_TIPS,"msg":(getLanTextByKey("SUCCESS_GET_CARD_NUMBER_DESC").replace("%1",card))};
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);
		g_item.szCard = card;
		modifyEmpInfoRelateUI(g_item);
		g_item = null;
		g_isAddingEmpInfo = false;
	}
  displayWinCloseIcon(true,STATUS_POP_WIN_DEFAULT_ID);
	if(!g_isHasCallbackError)
		setTimeout(function(){removeControlById(STATUS_POP_WIN_DEFAULT_ID);delaySetMask();},1000);
	return;
}
function usbAddCard(btn)
{
	var usbAddCard = document.getElementById("txt_usb_add_card");
	usbAddCard.hideContent = (document.getElementById(btn.btnid)).hideContent;
	var oJson = {"mode":LOG_NORMAL_TIPS,"msg":getLanTextByKey("T_PERMISSION_KEYBOARD_INPUT_DESC")};
	insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);
	g_isForceUSRAddCardInputFocus = true;
	usbAddCard.focus();	
}
var g_curTimeStamp = -1;
var g_keyboardInputIsTips = false;
function usbAddCardNumber(obj)
{
	var span = 50;
	var timestamp = (new Date()).getTime();
	if(timestamp - g_curTimeStamp > span & g_curTimeStamp != -1)
	{
		obj.value = "";	
		if(!g_keyboardInputIsTips)
		{
			var oJson = {"mode":LOG_ERROR_TIPS,"msg":getLanTextByKey("T_KEYBOARD_INPUT_NO_DATA_TIPS")};
			insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);
			g_keyboardInputIsTips = true;
			displayWinCloseIcon(true,STATUS_POP_WIN_DEFAULT_ID)
		}
		return;	
	} 
  
	g_curTimeStamp = timestamp;
	var cardNumber = delForeCharByString("0",obj.value);
	obj.szCard = cardNumber; 
  
  //2021-01-04：增加结束检测代码  
  //是否开启检测
  if(!g_isStartCheckIsEnd)
  {
    g_isStartCheckIsEnd = true;
    g_setInterval = setInterval('startCheckIsEnd();', 200);
  }
}
//2021-01-04：增加结束检测代码 
//检测方法
var g_isStartCheckIsEnd = false;
var g_setInterval = null;
function startCheckIsEnd()
{  
  var span = 300;
	var timestamp = (new Date()).getTime();
	if(timestamp - g_curTimeStamp > span & g_curTimeStamp != -1)
	{
    completeUsbAddCardNumber(document.getElementById("txt_usb_add_card"));
  }
}
function completeUsbAddCardNumber(obj)
{
	g_curTimeStamp = -1;
	g_keyboardInputIsTips = false;
	obj.value = "";
	document.getElementById("txt_card_number").value = obj.szCard;
	var btn = document.getElementById("btn_save_card_number");
	setIcoAbtnStatus(btn,false);
	removeControlById(STATUS_POP_WIN_DEFAULT_ID);
	addEmpCardNumber(btn);
	g_isForceUSRAddCardInputFocus = false;
	setIcoAbtnStatus(btn,true);
  g_isCompleteUsbAddCardNumber = true;//2021-01-04：增加结束检测代码
}
function usbAddCardNumber1(txt)
{
	var cardNumber = delForeCharByString("0",txt.value);
	txt.value = '';
	document.getElementById("txt_card_number").value = cardNumber;
	//(txt.hideContent).szCard = cardNumber;
	setTimeout(function(){removeControlById(STATUS_POP_WIN_DEFAULT_ID);addEmpCardNumber(txt);},1000);
}
function delForeCharByString(char,str)
{
	var delChars = '';
	for(var i = 0; i<str.length; i++)
	{
		if(str.charAt(i) == '0')
			delChars += '0';
		else
			break;
	}
	return str.replace(delChars,"");
}
//删除人员指纹代码////////////////////////////////////////////////////////////////////////////
function confirmDelFinger(btn)
{
	if(btn.disabled)
		return;
	g_control = btn;
	var item = g_control.hideContent;	
	if(!item.bFingerprint1 && !item.bFingerprint2 && !item.bFingerprint3)	
		return;
	var sConfirm = new customConfirm();
	btn.disabled = true;
	var tips = getLanTextByKey("T_DEL_FINGER_TIPS").replace("%1",'<span style="color:#cd1a1a;">\"' + item.szName + '\"</span>');
	//new Array(((item.bFingerprint1)?1:0),((item.bFingerprint2)?1:0),((item.bFingerprint3)?1:0))
	var numStr = (item.bFingerprint1)?'1':"";
	if(item.bFingerprint2 && numStr.length > 0)
		numStr += ", ";
	numStr += (item.bFingerprint2)?'2':"";
	if(item.bFingerprint3 && numStr.length > 0)
		numStr += ", ";
	numStr += (item.bFingerprint3)?'3':"";
	if(numStr == "")
		return;
	tips = tips.replace("%2",'<span style="color:#cd1a1a;">' + numStr + '</span>');
	sConfirm.init(tips,"callBackConfirmDelFinger",CONFIRM_DIALOG_MASK_TIP_MODE);
	btn.disabled = false;
}
function callBackConfirmDelFinger(isDel)
{
	if(isDel)
		DelFingerprint(g_control);
}
function DelFingerprint(btn)
{	
	//if(!confirm(getLanTextByKey("T_DEL_ITEM_TIPS")))
	//	return;
	var index = -1;//删除三枚指纹
	var item = btn.hideContent;
	item.deviceMode = FINGER_MODE;
	item.mode = EMP_DEL_FINGER_MODE;
	item.index = index;
	g_item = item;
	var ret = _externalDelFintgerprint('OnDelFintgerprint', item.nID/*人员ID*/, item.index/*第几号指纹0~2，-1表示所有指纹*/, item.szName/*人员姓名，将传入系统日志*/);
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作
		startProcess(4, null);
		return 0;
	}
	showToast(err.szMsg,DIALOG_MASK_TIP_MODE,2);
	cancelProcess(null, 4);
}
function OnDelFintgerprint(szRet)
{
	eval('var err = ' + szRet);
	//err.nCode 错误码。大于等于0时表示无错误且为设备的ID号。szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	var oJson = null;
	if (err.nCode < 0)
		oJson = {"mode":2,"msg":err.szMsg};
	else
		oJson = {"mode":1,"msg":"已经删除指纹"};
	modifyEmpInfoRelateUI(g_item);
	g_item = null;
	//insertStatusItem("log_status_list",oJson);
	
	setTimeout(function(){cancelProcess(null, 4);},10);
}
//测试采集仪是否已连接代码////////////////////////////////////////////////////////////////////////////
function DetectFPCollector()
{
	return _externalDetectFPCollector();
}
//采集仪采集指纹代码////////////////////////////////////////////////////////////////////////////
function CollectFPByCollector(item,addInfoDevice,index)
{
	g_item = item;
	g_countGetFingerTimes = 0;
  g_isHasCallbackError = false;
	var ret = _externalCollectFPByCollector('onCollectFPByCollector', item.nID/*人员ID*/, index/*第几号指纹0~2*/, item.szName/*人员姓名，将传入系统日志*/);
	eval ('var err = ' + ret);
	//err.nCode 错误码。大于等于0时表示无错误szMsg成员无效。小于0时表示出错。
	//err.szMsg 当出错时该成员才有效，包含错误的文本信息。
	if (err.nCode >= 0)
	{
		//此处应禁用所有按钮，只允许取消按钮可以操作		
		//insertStatusTabItem(STATUS_LIST_DEFAULT_ID,{"mode":LOG_NORMAL_TIPS,"msg":"指纹采集仪开始采集指纹......"});	
		return 0;
	}
	insertStatusTabItem(STATUS_LIST_DEFAULT_ID,{"mode":LOG_ERROR_TIPS,"msg":err.szMsg});
	g_item = null;
}
var g_countGetFingerTimes = 0;
function onCollectFPByCollector(szRet)
{
	eval('var item = ' + szRet);
	var oJson = "";
	if (item.nCode == 1)//采集线程已启动，同时表明采集仪也是连接好的
	{
		oJson = {"mode":LOG_NORMAL_TIPS,"msg":getLanTextByKey("USB_ATTENDANCE_DEVICE_GET_DESC")};
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);	
		oJson = {"mode":LOG_IMPORTANT_TIPS,"msg":getLanTextByKey("PLS_PRESS_FINGER_DESC")};
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);
		return;
	}
	else if (item.nCode == 2)
	{
		//中间过程未松开手指
		oJson = {"mode":LOG_IMPORTANT_TIPS,"msg":getLanTextByKey("USB_ATTENDANCE_DEVICE_FINISH_DESC")};
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);
		modifyEmpInfoRelateUI(g_item);
		g_item = null;
		setTimeout(function(){removeControlById(STATUS_POP_WIN_DEFAULT_ID);delaySetMask();},1000);	
		return;
	}
	else if (item.nCode < 0)
	{
		//item.nCode为-3518时表明采集仪未连接到pc
		//item.nCode为-3519时表时三次采集合成错误
		//alert(item.szMsg);//同时也表示操作错误完成
		g_isHasCallbackError = true;
		oJson = {"mode":item.nCode,"msg":replaceStr(item.szMsg,"\n","<br/>")};
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);	
		if(item.nCode == -3518)
		{
			var obj = getLanTextKeyByMode(FINGER_MODE);
			var saveKey = obj["saveKey"];
			SetStore(saveKey,"-1",true);
			setUIdataByChangeFingerDevice(document.getElementById("btn_num_finger"),1,"-1");
		}
		g_item = null;	
	}
	else if (item.nCode == 3)
	{
		//中间过程未松开手指
		oJson = {"mode":LOG_WARN_TIPS,"msg":getLanTextByKey("PLS_LEAVE_FINGER_DESC")};
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);	
		return;
	}
	else if (item.nCode == 0)
	{
		//说明采集成功了一次		
		var oJson = {"mode":LOG_NORMAL_TIPS,"msg":((getLanTextByKey("FINISH_ATTENDANCE_TIME_DESC")).replace("%1","<span style='color:#ff0030;font-weight:bold;'>"+(++g_countGetFingerTimes)+"</span>"))};
		insertStatusTabItem(STATUS_LIST_DEFAULT_ID,oJson);	
		
		return;
	}
  displayWinCloseIcon(true,STATUS_POP_WIN_DEFAULT_ID);
	if(!g_isHasCallbackError)
		setTimeout(function(){removeControlById(STATUS_POP_WIN_DEFAULT_ID);delaySetMask();},STATUS_WIN_CLOSE_WATIT_TIME);
}
function deleSameCardNumber(cardNumber,id)
{
	var inputs = document.getElementsByTagName("input");
	for(var i = 0; i < inputs.length; i++)
	{
		if(inputs[i]["type"].toUpperCase() == "TEXT")
		{
			if(inputs[i].id != id & inputs[i].value == cardNumber)
			{
					inputs[i].value = inputs[i].tips;
					inputs[i].style.color ="#dedede";
			}
		}	
	}
}
/////////////////下面是老代码/////////////////////////////
function executeUSBaddCard()
{
	if(!checkIsStartProcess())
		startProcess(2,getStatusList(getLanTextByKey("STATUS_LIST_TITLE"),500,300,"log_status_list"));
	var usbAddCard = document.getElementById("txt_usb_add_card");
	var oJson = {"mode":1,"msg":getLanTextByKey("PERMISSION_KEYBOARD_INPUT_DESC")};
	insertStatusItem("log_status_list",oJson);
	usbAddCard.focus();
}
var g_USBdeviceCardNoStamp = 0;
var g_isFirstExecuteUSBdeviceCardNo = true;
function getUSBdeviceCardNo(txtObj,e)
{
	var timestamp = (new Date()).getTime();
	if(timestamp - g_USBdeviceCardNoStamp > IGNORE_KEYBOARD_INPUT_TIME & (!g_isFirstExecuteUSBdeviceCardNo))
	{
		//var oJson = {"mode":2,"msg":"：" + txtObj.value+",正在保存数据......"};
		//insertStatusItem("log_status_list",oJson);
		txtObj.value = "";//getLastCharInString(txtObj.value);
	}
	g_USBdeviceCardNoStamp = timestamp;
	g_isFirstExecuteUSBdeviceCardNo = false;
	txtObj.onfocus = null;
	if(e.keyCode != 13)
		return;
	var listInput = document.getElementById(g_btn.cid);	
	listInput.value = delConCharsInString(txtObj.value,"0",0,0);
	listInput.nID = (g_btn.hideContent).nID;
	var oJson = {"mode":1,"msg":((getLanTextByKey("READ_CARD_NUMBER_DESC")).replace("%1", listInput.value))};
	insertStatusItem("log_status_list",oJson);
	setTimeout(function(){CardByManual(listInput.value,listInput.nID,false);g_btn = null;},1000);
	txtObj.value = "";
	txtObj.onblur();	
}
function cardNumberRefocus(btn)
{
	btn.focus();	
}
//////////////////////人员的导入导出//////////////////////////////
//分步导出
function multiExportEmps(szPathFile,aEmps,aStyles,aIndex,startNum)
{
  var isFirst = false;console.log(szPathFile);
  if(szPathFile == null | szPathFile === "")
  {console.log("选择文件");
    var szFilter = "Excel Files(*.xlsx)|*.xlsx|";
    var szTitle = getLanTextByKey("T_EXPORT_EMP_SELECT_FILE_TIPS");
    //获取导出文件全路径名
    szPathFile = _externalSelectFile(szFilter, szTitle, true);
    console.log("szPathFile = " + szPathFile);
    if(szPathFile == null)
      return null;    
    
    isFirst = true;
  }
  aStyles = sortByaKeyVal(aStyles,aIndex,"index",true);
  var headerStr = "";
	var count = 0;	
  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 nRes = -1;
  var nCols = count;
  if(isFirst)
  {
    nRes = _externalExlBeginExport(szPathFile, nCols);
    eval('nRes = _externalExlExportRow(' + headerStr + ');');
  }
  //console.log("创建文件："+nRes); 
	if(!nRes)
	{
		endMultiExportEmps();
		return;
	}
	var rowStr = "";
	for(var i = 0; i < aEmps.length; i++)
	{
		count = 0;
		rowStr = "";
		
		//if(i == 0)console.log(aEmps[i]);
		var item = aEmps[i][aEmps[i].length - 1]["obj"];
		for(var j = 0; j < aEmps[i].length; j++)
		{
			if(aEmps[i][j]["index"] == COL_DEPT)
				item.nDepartment = aEmps[i][j]["val"];
			else if(aEmps[i][j]["index"] == COL_GENDER)			
				item.dwGender = aEmps[i][j]["val"];
			else if(aEmps[i][j]["index"] == COL_GROUP)
				item.dwFlag = aEmps[i][j]["val"];
		}
		for(var j = 0; j < aStyles.length; j++)
		{
			if(j == 0)
			{
				rowStr += '"'+(i + startNum) + '"';
				count++;
			}	
			else if(item[aStyles[j]["key"]] != undefined)
			{
				rowStr += ((count == 0)?'"':',"') + item[aStyles[j]["key"]] + '"';
				count++;
			}
		}
		eval('nRes = _externalExlExportRow(' + rowStr + ');');
		if(!nRes)
		{
			endMultiExportEmps();
			return;
		}
	}
	//endMultiExportEmps();
  return szPathFile;
}
function endMultiExportEmps()
{
  nRes = _externalExlEndExport();
  setTimeout(function(){g_startProc = true;cancelProcess(null,4);},100);
  setTimeout(function(){delaySetMask();},300);
}
/////////////////////一次性导出/////////////////////
function exportEmps(aEmps,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)
  {
    endMultiExportEmps();
    return null;
  }
	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 < aEmps.length; i++)
	{
		count = 0;
		rowStr = "";
		
		//if(i == 0)console.log(aEmps[i]);
		var item = aEmps[i][aEmps[i].length - 1]["obj"];
		for(var j = 0; j < aEmps[i].length; j++)
		{
			if(aEmps[i][j]["index"] == COL_DEPT)
				item.nDepartment = aEmps[i][j]["val"];
			else if(aEmps[i][j]["index"] == COL_GENDER)			
				item.dwGender = aEmps[i][j]["val"];
			else if(aEmps[i][j]["index"] == COL_GROUP)
				item.dwFlag = aEmps[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);
}
function getImportFilePath()
{
	//var szFilter = "Excel files(*.xlsx)|*.xlsx|"
   //               + "Excel Files (*.xls)|*.xls|";
  
 var szFilter = "Excel files(*.xlsx;*.xls)|*.xlsx;*.xls|";
                  
	var szTitle = getLanTextByKey("T_IMPORT_SELECT_FILE_TIPS");
	//获取导入文件全路径名(xls和xlsx文件都支持）
	var path = _externalSelectFile(szFilter, szTitle);
  console.log("path="+path);
  var aPath = path.split("\\");
  CURRENT_SELECT_DIR = "";
  for(var i = 0; i < aPath.length - 1; i++)
    CURRENT_SELECT_DIR += aPath[i] + "\\";
  
	return path;
}
var ERROR_READ_EXCEL_FILE = -1;
function getImportSheets()
{
	//打开导入文件
	var obj = {"szPathFile":getImportFilePath()};	
  return getExcelSheets(obj);
  /*
	var nRes = _externalLoadExcel(obj.szPathFile);
	//获取Excel文件内的sheet数与sheet名
	var ncSheet = _externalGetSheetCount();
	
  if(ncSheet === 0)
     obj["errorCode"] = ERROR_READ_EXCEL_FILE;
	obj.aSzName = Array();	
	for(var i = 0; i < ncSheet; i++)
		(obj.aSzName)[i] = _externalGetSheetName(i);//nIdx >= 0 && nIdx < ncSheet
	//上面的sheet名也可以由用户手动输入
	closeImportFile();
	return obj;
  */
}
function getImportRowCol(szPathFile)
{
	var szSheetName = $("#select_sheets").combobox("getText");
  return getExcelSheetRowCol(szPathFile,szSheetName);
  /*
	var nRes = _externalLoadExcel(szPathFile);
	nRes = _externalLoadSheet(szSheetName);
	var obj = {};
	//获取sheet的行数
	obj.nRows = _externalGetSheetRows();
	//获取sheet的列数
	obj.nCols = _externalGetSheetCols();
	//console.log(readExcelCell(0, 1));
 
	return obj;*/
}
function getImportCosSelectName(forceGetSoftwareData)
{
	var isForceGetSoftwareData = false;
	if(forceGetSoftwareData != undefined)
		isForceGetSoftwareData = forceGetSoftwareData;
	var aStyles = sortByaKeyVal(g_emp_data_tab_styles,g_emp_data_tab_aIndex,"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;
	}
}