//var loadFilterState="false";//筛选是否已加载完成
var loadUserState="false";//用户列表是否加载完成过
var G_filter = new Array();//用户信息全局变量
var G_col = 0;
//var G_descs = [false,true,false];//默认加载顺序
var pinyin = "ALL"; //当前用户列表所选的首字母标签
var G_sFilter = "";//筛选条件用
var selectusers="";//记录勾选用户信息
var tmpselectusers="";//记录上次勾选的用户信息
var tmpselectedAll="false";
/*-------------------------------------------------------经济人列表用------------------------------------*/
var list_customers_state="false";//加载客户列表状态—所有用户
//var list_groups_state="false";//加载客户列表状态—分组
var list_borkers_state="false";//加载客户列表状态—投顾
var list_managers_state="false";//加载客户列表状态—营销
var list_selected_state="false";//加载客户列表状态—营销
var G_filter_managers;//获取营销人员操作数组
var G_filter_brokers;//获取投顾人员操作数组
//var G_filter_groupslable; //获取分组操作数组
var G_filter_selecteds;//获取已选操作数组
var G_selecteds;//获取已选操作数组
var ilisttab="list_borkers";//记录当前分组标签id
var G_descs= [true,false,true,false,true,false,true,true,false,true,true];
//0：分组名称：1：投顾状态2：投顾姓名3：营销状态4：营销姓名5：客户在线状态6:客户姓名7：客户互动度8：已选在线状态9:已选姓名10：已选互动度
var tmpselectedAll_broker="false";
var tmpselectedAll_managers="false";

var chkall_managers_states="false";//记录营销全选状态
var chkall_brokers_states="false";//记录投顾全选状态
var chkall_users_states="false";//记录用户全选状态
var G_chkalls=[false,false,false,false];//临时数组，记录分组是否全选 0：分组 1：投顾 2：营销 3：客户
var changecolor=0;//为了统一隔行换色
/*-------------------------------------------------------经纪人列表结束----------------------------------*/
	//添加筛邮件样式
	function showselectcss()
	{	
		$(".mail_head").find("span:last").hover(function(){
			$(this).css("background-position","0px -19px");
		},function(){
			$(this).css("background-position","0px 0px");
		});
		
		$(".filter_list_up li").click(function(){
			if($(".filter_list_up dl").css("display") == "none")
			{
				$(".filter_list_up li").css("background","url(img/arr_top.gif) 186px center no-repeat");
				$(".filter_list_up dl").show();
				$(".filter_list_up .clear").show();
			}
			else
			{
				$(".filter_list_up li").css("background","url(img/arr_down.gif) 186px center no-repeat");
				$(".filter_list_up dl").hide();
				$(".filter_list_up .clear").hide();
			}
		});					
		var contentheight = $(window).height() - 40;
		$("#content").height(contentheight);
		
		$(window).resize(function() {
			var contentheight = $(window).height() - 40;
			$("#content").height(contentheight);
		});
	}
//筛邮件事件
	function showselect()
	{	
		initUsersData();//初始化数据
		//加载筛选条件	
		load_filter();
		//筛选条件收起
		$(".filter_list_up li").css("background","url(img/arr_down.gif) 186px center no-repeat");
		$(".filter_list_up dl").hide();
		$(".filter_list_up .clear").hide();
		//判断是否首次加载
		if(loadUserState=="false")
		{
			loadUserState="true";
			$(".mail_head").find("dd:last").click(function(){
				$("html").css("overflow-y","hidden");
				$("#content").show();
				$("#contentBtn").show();
				$(".wrapper").hide();						
			})
		}
		else
		{
			//加载上次保存时的缓存数据		
			chkall_managers_states=tmpselectedAll_managers;//记录营销全选状态
			chkall_brokers_states=tmpselectedAll_broker;//记录投顾全选状态
			chkall_users_states=tmpselectedAll;//记录用户全选状态
			
			selectusers=tmpselectusers;				
			SynchroniseSender(tmpselectusers,true);	
			if(tmpselectedAll=="true")
			{
				G_chkalls[3] = true;
				$("#thuserschk").attr("checked",true);
			}
			else
			{
				G_chkalls[3] = false;
				$("#thuserschk").attr("checked",false);
			}
			
			if(tmpselectedAll_broker=="true")
			{
				G_chkalls[1] = true;
				$("#thbrokerschk").attr("checked",true);
			}
			else
			{
				G_chkalls[1] = false;
				$("#thbrokerschk").attr("checked",false);
			}
		
			if(tmpselectedAll_managers=="true")
			{
				G_chkalls[2] = true;
				$("#thmanagerschk").attr("checked",true);
			}
			else
			{
				G_chkalls[2] = false;
				$("#thmanagerschk").attr("checked",false);
			}		
			
			if(tmpselectusers.length > 0 && tmpselectusers != "")
			{
				ilisttab="list_selected";
			//	changePinYin($("#mail_list_navigation_span_selected"),"Selected");	
			}else{
				ilisttab="list_borkers";
			}
		}
		G_filter = G_users;
		G_filter_managers =G_managers;
		G_filter_brokers =G_brokers;
		changelist(ilisttab);//分组标签显示	
	
	}
////筛选列表标签切换
//function changePinYin(ev,pinyinFilter)
//{
//	pinyin = pinyinFilter;
////	if ($(ev).hasClass("mail_list_navigation_span_sel"))
////		return;
//	$(ev).parent().parent().find("li span.mail_list_navigation_span_sel").toggleClass("mail_list_navigation_span_nosel").toggleClass("mail_list_navigation_span_sel");
//	$(ev).toggleClass("mail_list_navigation_span_nosel").toggleClass("mail_list_navigation_span_sel");
//	GetUserFilter();
//}

//function GetUserFilter()
//{
//
//	G_filter = $.grep(G_users,function(v){
//		return filterPinyin(pinyin,v);
//	});
////	recordtime("标签切换");
//	load_users(G_filter);
////	recordtime("重新加载用户列表");
//}
//按照拼音字母查找
function filterPinyin(pinyinselect,g_user)
{
	if (g_user["filter"] == true)
		return false;
	var value = g_user.fc.toUpperCase();
	switch (pinyinselect)
	{
		case 'ALL':
			return true;
		break;
		case 'A-D':
			if (value == "A" || value == "B" || value == "C" || value =="D")
			{
				return true;
			}
		break;
		case 'E-H':
			if (value == "E" || value == "F" || value == "G" || value =="H")
			{
				return true;
			}
		break;
		case 'I-L':
			if (value == "I" || value == "J" || value == "K" || value =="L")
			{
				return true;
			}
		break;
		case 'M-O':
			if (value == "M" || value == "N" || value == "O")
			{
				return true;
			}
		break;
		case 'P-R':
			if (value == "P" || value == "Q" || value == "R")
			{
				return true;
			}
		break;
		case 'S-U':
			if (value == "S" || value == "T" || value == "U")
			{
				return true;
			}
		break;
		case 'V-Z':
			if (value == "V" || value == "W" || value == "X" || value =="Y" || value =="Z")
			{
				return true;
			}
		break;
		case 'Selected':
			if(g_user.selectedStatus == 1)
			{
				return true;
			}
		break;
	}
	return false;
}

////首次加载用户数据
//function sortusers(users)
//{
//	var l_users;
//	switch (G_col)
//	{
//	case 2:
//		if (G_descs[G_col])
//		{
//			$("#span_do").text("↑");
//		}
//		else
//		{
//			$("#span_do").text("↓");
//		}
//		$("#span_status").text("");
//		$("#span_name").text("");
//		l_users = users.sort(function(a,b) {
//			if (G_descs[2])
//			{
//				if(parseFloat(a.interactLvl) > parseFloat(b.interactLvl)) return -1;
//				if(parseFloat(a.interactLvl) < parseFloat(b.interactLvl)) return 1;
//				return 0;
//			}
//			else
//			{
//				if(parseFloat(a.interactLvl) < parseFloat(b.interactLvl)) return -1;
//				if(parseFloat(a.interactLvl) > parseFloat(b.interactLvl)) return 1;
//				return 0;
//			}
//		})
//	break;
//	case 1:
//		if (G_descs[G_col])
//		{
//			$("#span_name").text("↑");
//		}
//		else
//		{
//			$("#span_name").text("↓");
//		}
//		$("#span_status").text("");
//		$("#span_do").text("");
//		l_users = users.sort(function(a,b) {
//			if (G_descs[1])
//			{			
//				if(a.qp > b.qp) return -1;
//				if(a.qp < b.qp) return 1;
//				return 0;
//			}
//			else
//			{
//				if(a.qp < b.qp) return -1;
//				if(a.qp > b.qp) return 1;
//				return 0;
//			}
//		})
//	break;
//	case 0:
//	default:
//		if (G_descs[G_col])
//		{
//			$("#span_status").text("↑");
//		}
//		else
//		{
//			$("#span_status").text("↓");
//		}
//		$("#span_name").text("");
//		$("#span_do").text("");
//		l_users = users.sort(function(a,b) {
//		if (G_descs[2])
//		{
//				if(parseFloat(a.interactLvl) > parseFloat(b.interactLvl)) return -1;
//				if(parseFloat(a.interactLvl) < parseFloat(b.interactLvl)) return 1;
//				return 0;
//			}
//			else
//			{
//				if(parseFloat(a.interactLvl) < parseFloat(b.interactLvl)) return -1;
//				if(parseFloat(a.interactLvl) > parseFloat(b.interactLvl)) return 1;
//				return 0;
//			}
//		})
//		l_users = users.sort(function(a,b) {
//			if (G_descs[0])
//			{
//				if(a.ol > b.ol) return -1;
//				if(a.ol < b.ol) return 1;
//				return 0;
//			}
//			else
//			{
//				if(a.ol < b.ol) return -1;
//				if(a.ol > b.ol) return 1;
//				return 0;
//			}
//		})
//	break;
//	}
//	return l_users;
//}

function SynchroniseSender(textValue,chg)
{
	if($.trim(textValue).length > 0 && textValue != "")
	{
		if(textValue.indexOf(";") >= 0)
		{
			var users = textValue.split(";");
			$.each(G_users,function(i,g_user){
				if (($.inArray(g_user.nm,users) < 0) && ($.inArray(g_user.id,users) < 0))
				{
					this.selectedStatus = 0;
				}
				else
				{
					this.selectedStatus = 1;
				}
			});
			$.each(G_managers,function(i,g_user){
				if (($.inArray(g_user.nm,users) < 0) && ($.inArray(g_user.id,users) < 0))
				{
					this.selectedStatus = 0;
				}
				else
				{
					this.selectedStatus = 1;
				}
			});
			$.each(G_brokers,function(i,g_user){
				if (($.inArray(g_user.nm,users) < 0) && ($.inArray(g_user.id,users) < 0))
				{
					this.selectedStatus = 0;
				}
				else
				{
					this.selectedStatus = 1;
				}
			});
		}
		else
		{
			$.each(G_users,function(){
				if ((this.nm != textValue) && (this.id != textValue))
				{
					this.selectedStatus = 0;
				}
				else
				{
					this.selectedStatus = 1;
				}
			});
			$.each(G_managers,function(){
				if ((this.nm != textValue) && (this.id != textValue))
				{
					this.selectedStatus = 0;
				}
				else
				{
					this.selectedStatus = 1;
				}
			});
			$.each(G_brokers,function(){
				if ((this.nm != textValue) && (this.id != textValue))
				{
					this.selectedStatus = 0;
				}
				else
				{
					this.selectedStatus = 1;
				}
			});
		}
	}
	else
	{
		$.each(G_users,function(){
			this.selectedStatus = 0;
		});
		$.each(G_managers,function(){
			this.selectedStatus = 0;
		});
		$.each(G_brokers,function(){
			this.selectedStatus = 0;
		});
	}
//	if (chg == true)
//	{
//		load_users(G_filter);
//	}
}

//勾选事件
function chgSender(value)
{
	var userid = $(value).attr("userid");
	var user = $.grep(G_users,function(g_user,i){return g_user.id == userid;});
	if(value.checked)
	{		
		user[0].selectedStatus = 1;
	}
	else
	{
		user[0].selectedStatus = 0;
	}
	
	var sendername = selectusers;
	sendername = $.trim(sendername).split(";");
	var sid = $(value).attr("userid");
	if (sendername != null)
	{
		if (value.checked)
		{
			if ($.inArray(sid,sendername) < 0)
			{
				sendername.push(sid);
			}
		}
		else
		{
			sendername = $.grep(sendername,function(val,key){return val != sid;});

		}
		sendername = $.grep(sendername,function(val,key){return val != "";});
		selectusers=sendername.join(";");
	}
	else
	{
		selectusers=sid;
	}

}
function checkboxeline(obj)
{
//	$(obj).find("input").each(function(){
//		this.checked = !this.checked;
//		chgSender(this);
//	});
}



var NeedLoadUsers = false;
var cacheuser = null;
var cacheindex = 0;
//加载用户列表第一页，后继由延时加载函数加载
function load_users(users)
{
	var shtml = new Array();
	recordtime("设置用户是否选中完成(当回复或平台调用时会有选中用户)");
	var l_users = sortusers(users);
	recordtime("排序完成");
	cacheuser = l_users;
	cacheindex = cacheuser.length-1;

	if(cacheindex%2==0){
		changecolor=0;
	}else{
		changecolor=1;
	}
	for (var i=cacheuser.length-1; i >=0; i--){
		if(cacheindex%2==changecolor){
			if(cacheuser[i].selectedStatus == 1){
				shtml.push('<dd style="width:25px;background:#fff;"><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'" onclick="javascript:chgSender(this); stopBubble(event);" checked="checked" /></dd>');
			}else{
				shtml.push('<dd style="width:25px;background:#fff;"><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'" onclick="javascript:chgSender(this); stopBubble(event);" /></dd>');
			}
			if (cacheuser[i].ol == "0"){
				shtml.push('<dd style="width:43px;background:#fff;"><img src="img/people.gif" /></dd>');
			}else{
				shtml.push('<dd style="width:43px;background:#fff;"><img src="img/people_online.gif" /></dd>');
			}
			shtml.push('<dd class="ddtext over" style="width:55px;background:#fff;" title="'+ cacheuser[i].nm +'" >'+ cacheuser[i].nm +'</dd>');
			shtml.push('<dd class="ddtext" style="width:50px;background:#fff; padding-left:13px;" >'+ cacheuser[i].interactLvl +'</dd>');		
		}else{
			if(cacheuser[i].selectedStatus == 1){
				shtml.push('<dd style="width:25px;background:#E4F5FF;"><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'" onclick="javascript:chgSender(this); stopBubble(event);" checked="checked" /></dd>');
			}else{
				shtml.push('<dd style="width:25px;background:#E4F5FF;"><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'" onclick="javascript:chgSender(this); stopBubble(event);" /></dd>');
			}
			if (cacheuser[i].ol == "0"){
				shtml.push('<dd style="width:43px;background:#E4F5FF;"><img src="img/people.gif" /></dd>');
			}else{
				shtml.push('<dd style="width:43px;background:#E4F5FF;"><img src="img/people_online.gif" /></dd>');
			}
			shtml.push('<dd class="ddtext over" style="width:55px;background:#E4F5FF;" title="'+ cacheuser[i].nm +'" >'+ cacheuser[i].nm +'</dd>');
			shtml.push('<dd class="ddtext" style="width:50px;background:#E4F5FF; padding-left:13px;" >'+ cacheuser[i].interactLvl +'</dd>');
		}
		cacheindex--;
	//	if (cacheindex <= cacheuser.length-31) break;
	}
/*	for (var i=cacheuser.length-1; i >=0; i--)
	{
		shtml.push('<tr style="background:#fff;" onclick="javascript:checkboxeline(this);">');
		if(cacheuser[i].selectedStatus == 1)
		{
			shtml.push('<td><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'" onclick="javascript:chgSender(this); stopBubble(event);" checked="checked" /></td>');
		}
		else
		{
			shtml.push('<td><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'" onclick="javascript:chgSender(this); stopBubble(event);" /></td>');
		}
		if (cacheuser[i].ol == "0")
		{
			shtml.push('<td><img src="img/people.gif" /></td>');
		}
		else
		{
			shtml.push('<td><img src="img/people_online.gif" /></td>');
		}
		shtml.push('<td id="name'+ cacheuser[i].id +'">'+ cacheuser[i].nm +'</td>');
		shtml.push('<td style="padding-left:16px;" id="interact'+ cacheuser[i].id+'">'+ cacheuser[i].interactLvl +'</td>');
		shtml.push('</tr>');
		
		cacheindex--;
		if (cacheindex <= cacheuser.length-31) break;
	}
*/
	var html = shtml.join("");
	$("#tbuserlist").html(html);
	$("#tbuserlist tr:odd").css("background","#E4F5FF");	
	if (cacheindex > 0) {
		NeedLoadUsers = true;
		setTimeout("DelayLoadUsers()", 25);
	}
	else
	{
		$("#thuserschk").attr("style","");
		G_load_users = true;
	}
}

//延时加载客户列表函数
function DelayLoadUsers()
{
	var shtml = new Array();
	for (var i = 0; i < 30; i++)
	{
		if (typeof(cacheuser[cacheindex]) == "undefined") break;
		
		if(cacheindex%2==changecolor){
			if(cacheuser[cacheindex].selectedStatus == 1){
				shtml.push('<dd style="width:25px;background:#fff;"><input id="chk'+ cacheuser[cacheindex].id +'" userid="' + cacheuser[cacheindex].id + '" type="checkbox" username="'+ cacheuser[cacheindex].nm +'" onclick="javascript:chgSender(this); stopBubble(event);" checked="checked" /></dd>');
			}else{
				shtml.push('<dd style="width:25px;background:#fff;"><input id="chk'+ cacheuser[cacheindex].id +'" userid="' + cacheuser[cacheindex].id + '" type="checkbox" username="'+ cacheuser[cacheindex].nm +'" onclick="javascript:chgSender(this); stopBubble(event);" /></dd>');
			}
			if (cacheuser[cacheindex].ol == "0"){
				shtml.push('<dd style="width:43px;background:#fff;"><img src="img/people.gif" /></dd>');
			}else{
				shtml.push('<dd style="width:43px;background:#fff;"><img src="img/people_online.gif" /></dd>');
			}
			shtml.push('<dd class="ddtext over" style="width:55px;background:#fff;" title="'+ cacheuser[i].nm +'" >'+ cacheuser[cacheindex].nm +'</dd>');
			shtml.push('<dd class="ddtext" style="width:50px;background:#fff;padding-left:13px;" >'+ cacheuser[cacheindex].interactLvl +'</dd>');
		}else{
			if(cacheuser[cacheindex].selectedStatus == 1){
				shtml.push('<dd style="width:25px;background:#E4F5FF;"><input id="chk'+ cacheuser[cacheindex].id +'" userid="' + cacheuser[cacheindex].id + '" type="checkbox" username="'+ cacheuser[cacheindex].nm +'" onclick="javascript:chgSender(this); stopBubble(event);" checked="checked" /></dd>');
			}else{
				shtml.push('<dd style="width:25px;background:#E4F5FF;"><input id="chk'+ cacheuser[cacheindex].id +'" userid="' + cacheuser[cacheindex].id + '" type="checkbox" username="'+ cacheuser[cacheindex].nm +'" onclick="javascript:chgSender(this); stopBubble(event);" /></dd>');
			}
			if (cacheuser[cacheindex].ol == "0"){
				shtml.push('<dd style="width:43px;background:#E4F5FF;"><img src="img/people.gif" /></dd>');
			}else{
				shtml.push('<dd style="width:43px;background:#E4F5FF;"><img src="img/people_online.gif" /></dd>');
			}
			shtml.push('<dd class="ddtext over" style="width:55px;background:#E4F5FF;" title="'+ cacheuser[i].nm +'" >'+ cacheuser[cacheindex].nm +'</dd>');
			shtml.push('<dd class="ddtext" style="width:50px;background:#E4F5FF;padding-left:13px;" >'+ cacheuser[cacheindex].interactLvl +'</dd>');
		}
	/*	shtml.push('<tr style="background:#fff;" onclick="javascript:checkboxeline(this);">');
		if(cacheuser[cacheindex].selectedStatus == 1)
		{
			shtml.push('<td><input id="chk'+ cacheuser[cacheindex].id +'" userid="' + cacheuser[cacheindex].id + '" type="checkbox" username="'+ cacheuser[cacheindex].nm +'" onclick="javascript:chgSender(this); stopBubble(event);" checked="checked" /></td>');
		}
		else
		{
			shtml.push('<td><input id="chk'+ cacheuser[cacheindex].id +'" userid="' + cacheuser[cacheindex].id + '" type="checkbox" username="'+ cacheuser[cacheindex].nm +'" onclick="javascript:chgSender(this); stopBubble(event);" /></td>');
		}
		if (cacheuser[cacheindex].ol == "0")
		{
			shtml.push('<td><img src="img/people.gif" /></td>');
		}
		else
		{
			shtml.push('<td><img src="img/people_online.gif" /></td>');
		}
		shtml.push('<td id="name'+ cacheuser[cacheindex].id +'">'+ cacheuser[cacheindex].nm +'</td>');
		shtml.push('<td style="padding-left:16px;" id="interact'+ cacheuser[cacheindex].id+'">'+ cacheuser[cacheindex].interactLvl +'</td>');
		shtml.push('</tr>');
		*/
		cacheindex--;
		if (cacheindex <= -1) break;
	}
	
	var html = shtml.join("");
	$("#tbuserlist").append($(html));
	$("#tbuserlist tr:odd").css("background","#E4F5FF");	
	recordtime("第n次加载客户列表完成");

	if (cacheindex >-1) {
		setTimeout("DelayLoadUsers()", 25);
	} else {
		// 选择用户操作
		G_load_users = true;
		$("#thuserschk").attr("style","");
		if (G_loaded == false)
		{
			recordend();
			G_loaded = true;
		}
	}
}

////排序
//function orderlist(value)
//{	
//	switch (value)
//	{
//	case "status":
//		if ($("#span_status").text() == "↑")
//		{
//			$("#span_status").text("↓");
//		}
//		else
//		{
//			$("#span_status").text("↑");
//		}
//		$("#span_name").text("");
//		$("#span_do").text("");
//		break;
//	case "name":
//		if ($("#span_name").text() == "↑")
//		{
//			$("#span_name").text("↓");
//		}
//		else
//		{
//			$("#span_name").text("↑");
//		}
//		$("#span_status").text("");
//		$("#span_do").text("");
//		break;
//	case "do":
//		if ($("#span_do").text() == "↑")
//		{
//			$("#span_do").text("↓");
//		}
//		else
//		{
//			$("#span_do").text("↑");
//		}
//		$("#span_status").text("");
//		$("#span_name").text("");
//		break;
//	}
//	G_col = value;
//	G_descs[G_col] = !G_descs[G_col];
//	load_users(G_filter);
//}



//添加筛选条件
function load_filter()
{
		var sdlstring = "<div style=\" height:100%; float:left;\">";
		for (var i=0; G_groups != null && i < G_groups.length; i++)
		{
			sdlstring = sdlstring + '<dd><label><input type="checkbox" onclick="javascript:GetUserFilterOK();stopBubble(event);" groupid="' + G_groups[i].id + '"/></label>' + G_groups[i].name + '</dd>';
		}
		sdlstring += '</div>';
		$("#dlGroup").html("<dt style='position:relative; left:0; top:50%; padding:0 2px 0 0; margin-top:-23px;'>用<br />户<br />标<br />签</dt>" + sdlstring);	
		sdlstring = "<div style=\" height:100%; float:left;\">";
		for (var i=0; i < G_Actions.length; i++)
		{
			sdlstring += '<dd><label><input type="checkbox" onclick="javascript:GetUserFilterOK();stopBubble(event);" actionid="' + G_Actions[i].id + '"/></label>' + G_Actions[i].name + '</dd>';
		}
		sdlstring += '</div>';
		$("#dlAction").html("<dt style='position:relative; left:0; top:50%; padding:0 2px 0 0; margin-top:-23px;'>行<br />为<br />倾<br />向</dt>" + sdlstring);	
		
		/*长期权限
		sdlstring = "";
		for (var key in G_Rights)
		{
			if (G_Rights[key].type=="1")
			{
				sdlstring += '<dd><label><input type="checkbox" onclick="javascript:GetUserFilterOK();stopBubble(event);" rightid="' + key + '"/></label>' + G_Rights[key].nm + '</dd>';
			}
		}	
		$("#dlRight").html("<dt>权<br /><br />限</dt>" + sdlstring);	
		*/
		
		//试用产品 type=3
		sdlstring = "<div style=\" height:100%; float:left;\">";
		for (var key in G_Rights)
		{
			if (G_Rights[key].type=="3")
			{
				sdlstring += '<dd style="width:170px;"><label><input type="checkbox" onclick="javascript:GetUserFilterOK();stopBubble(event);" rightid="' + key + '"/></label>' + G_Rights[key].nm + '</dd>';
			}		
		}
		sdlstring += '</div>';
		$("#dlTrialRight").html("<dt style='position:relative; left:0; top:50%; padding:0 2px 0 0; margin-top:-23px;'>试<br />用<br />产<br />品</dt>" + sdlstring);
	
}

//确定筛选条件
function GetUserFilterOK()
{	
	popupDiv("show");//显示等待进度条
			$("#tbuserlist").hide();
	setTimeout("GetUserFilterOKInit()",0);
}
function popupDiv(value)
{
	if (value=="show")
	{
 		$("#loading_mail_select").show();
 	}
 	else
 	{
 		$("#loading_mail_select").hide();
 	}
}
//执行筛选条件
function GetUserFilterOKInit()
{
g_isd=0;
srecordstart="";
G_loaded = false;
//recordstart(0);
records = new Array();	
$("#showtime").html("");
recordtime("清空前边记录");
recordtime("筛选开始");
	//数组遍历开始记录开始
 /*长期权限数组
 	var dlRight=new Array();
	$("#dlRight dd").find("input").each(function(idx,vle){
		if(this.checked)
		{
			var rightKey = $(this).attr("rightid");
			if ($.inArray(rightKey,dlRight) < 0)
			{
				dlRight.push(rightKey);			
			}			
		}
	});
*/
	//试用权限
	var dlTrialRight=new Array();
	$("#dlTrialRight dd").find("input").each(function(idx,vle){
		if(this.checked)
		{
			var rightKey = $(this).attr("rightid");
			if ($.inArray(rightKey,dlTrialRight) < 0)
			{
				dlTrialRight.push(rightKey);			
			}			
		}
	});

	var dlAction=new Array();
	$("#dlAction dd").find("input").each(function(idx,vle){
		if(this.checked)
		{
			var actionKey = $(this).attr("actionid");
			if ($.inArray(actionKey,dlAction) < 0)
			{
				dlAction.push(actionKey);			
			}			
		}
	});

	var dlGroup=new Array();
	$("#dlGroup dd").find("input").each(function(idx,vle){
		if(this.checked)
		{
			var groupKey = $(this).attr("groupid");
			if ($.inArray(groupKey,dlGroup) < 0)
			{
				dlGroup.push(groupKey);			
			}			
		}
	});
	//数组记录结束	
	$(G_users).each(function(userindex,uservalue){
		var tmpFlag = true;
		
		/*长期权限
		if(dlRight.length>0)
		{
			for(var i=0 ;i< dlRight.length;i++)
			{
				var tmpkey=dlRight[i];
				if(typeof(uservalue["srv"]) == "undefined")
				{
					tmpFlag = false;
					break;
				}
				else
				{
					if(typeof(uservalue["srv"][tmpkey]) == "undefined")
					{
						tmpFlag = false;
						break;
					}
				}
			}		
		}
		*/
		//试用权限
		if(dlTrialRight.length>0)
		{
			for(var i=0 ;i< dlTrialRight.length;i++)
			{
				var tmpkey= dlTrialRight[i];			
				if(typeof(uservalue["srv"]) == "undefined")
				{
					tmpFlag = false;
					break;
				}
				else
				{
					if(typeof(uservalue["srv"][tmpkey]) == "undefined")
					{
						tmpFlag = false;
						break;
					}
				}
			}		
		}
		if(tmpFlag)
		{
			if(dlAction.length>0)
			{
				for(var i=0 ;i< dlAction.length;i++)
				{
					var tmpkey=dlAction[i];
					if(typeof(uservalue["act"]) == "undefined")
					{
						tmpFlag = false;
						break;
					}
					else
					{
						var isexist = false;
						$.each(uservalue["act"],function(index,v){
							if (v.id == tmpkey)
							{
								isexist = true;
								return;
							}
						});
						if (isexist != true)
						{
							tmpFlag = false;
							break;
						}
					}
				}
			}
		}
		if(tmpFlag)
		{
			if(dlGroup.length>0)
			{
				for(var i=0 ;i< dlGroup.length;i++)
				{
					var tmpkey=dlGroup[i];
					if(typeof(uservalue["group"]) == "undefined")
					{
						tmpFlag = false;
						break;
					}
					else
					{
						var isexist = false;
						$.each(uservalue["group"],function(index,v){
							if (v.toString() == tmpkey.toString())
							{
								isexist = true;
								return;
							}
						});
						if (isexist != true)
						{
							tmpFlag = false;
							break;
						}
					}
				}
			}		
		}		
		G_users[userindex]["filter"] = !tmpFlag;
	});
//recordtime("判断界面勾选的筛选条件");
	GetUserFilter();
//recordtime("筛选结束");
	popupDiv("hide");
$("#tbuserlist").show();
//recordend();

}
//清楚用户列表删选内容
/*
function clearChecked()
{
	pinyin = "ALL"; 	
	selectusers="";
	G_sFilter="";
	$("#dlRight dd").find("input").each(function(){this.checked = false});//
	$("#dlAction dd").find("input").each(function(){this.checked = false});
	$("#dlGroup dd").find("input").each(function(){this.checked = false});
	
	$("#tbuserlist").find("input").each(function(index,value){value.checked = false;});
	$("#thuserschk").attr("checked",false);
	
	$(G_users).each(function(index,value){value["selectedStatus"] = 0;});	
	$(G_users).each(function(index,value){value["filter"] = false;});
	G_filter = G_users;
	searchTXT("Inbox");	
	searchTXT("Sent");	
	
	
}
*/
//判断当前筛选框是否显示勾选图片
function UserFilterImgStates()
{
	//判断添加筛选图片
	if (selectusers.length > 0)
	{	
		$("#ddmailselect1").children("span").css("background-position","0px -38px");
		$("#ddmailselect2").children("span").css("background-position","0px -38px");
		$(".mail_head").find("span:last").hover(function(){
			$(this).css("background-position","0px -38px");
		});
	}
	else
	{
		$("#ddmailselect1").children("span").css("background-position","0px 0px");
		$("#ddmailselect2").children("span").css("background-position","0px 0px");
		$(".mail_head").find("span:last").hover(function(){
			$(this).css("background-position","0px -19px");
		},function(){
			$(this).css("background-position","0px 0px");
		});
	}
}
//筛选确定
function selectOK()
{	
	//给临时变量赋值
	tmpselectusers = selectusers;
	if($("#thuserschk").attr("checked"))
	{
		tmpselectedAll="true";
	}
	else
	{
		tmpselectedAll="false";
	}	
	if($("#thmanagerschk").attr("checked"))
	{
		tmpselectedAll_managers="true";
	}
	else
	{
		tmpselectedAll_managers="false";
	}
	if($("#thbrokerschk").attr("checked"))
	{
		tmpselectedAll_broker="true";
	}
	else
	{
		tmpselectedAll_broker="false";
	}
	//判断添加筛选图片
	UserFilterImgStates();
	//筛邮件隐藏
	$("#content").hide();
	$("#contentBtn").hide();
	$("html").css("overflow-y","scroll");
	$(".wrapper").show();	
	searchTXT("Inbox");	
	searchTXT("Sent");	
}
//筛选取消
function selectCancel()
{
//	clearChecked();//删除界面勾选
//	GetUserFilter();//重置筛选用户列表数据
//	//判断添加筛选图片
//	UserFilterImgStates();
	//筛邮件隐藏
	$("#content").hide();
	$("#contentBtn").hide();
	$("html").css("overflow-y","scroll");
	$(".wrapper").show();
}




//_________________________________________________________________________________________________________________________



/*
*用户列表标签切换
*/
function changelist(evid)
{
	if ($("#"+evid).hasClass("mail_list_sel"))
	{
	
	}
	else
	{
		$("#list_groups").attr("class","mail_list_nosel");
		$("#list_borkers").attr("class","mail_list_nosel");
		$("#list_managers").attr("class","mail_list_nosel");
		$("#list_customers").attr("class","mail_list_nosel");
		$("#list_selected").attr("class","mail_list_nosel");
		$("#"+evid).attr("class","mail_list_sel")
	}
	$("#table_grouplist").hide();
	$("#table_borkerlist").hide();
	$("#table_managerlist").hide();
	$("#table_userlist").hide();
	$("#table_selectedlist").hide();
	switch (evid)
	{
//		case "list_groups":		
//			G_col=0;
//			G_filter_groupslable=G_groupslable;	
//			$("#mail_list_item_table").attr("class","mail_list_item item_more");
//			$("#btn_filter").hide();
//			$("#list_navigation").hide();
//			$("#table_grouplist").show();
//			LoadUserFirstTime(evid);//首次加载客户列表
//			list_groups_state="true";
//			break;
		case "list_borkers":
			G_col=1;
			$("#thbrokerschk").attr("style","display:none");
			Update_AllBrokers_online();//更新投顾在线状态
			G_filter_brokers =G_brokers;
			$("#mail_list_item_table").attr("class","mail_list_item item_less");
			$("#filter_list_up").hide();
			$("#list_navigation").show();
			$("#table_borkerlist").show();
			LoadUserFirstTime(evid);//首次加载客户列表
			list_borkers_state="true";
			$("#thbrokerschk").attr("style","");
			if(chkall_brokers_states=="true"){
				$("#thbrokerschk").attr("checked",true);
			}else{
				$("#thbrokerschk").attr("checked",false);
			}
			break;
		case "list_managers":
			G_col=3;
			$("#thmanagerschk").attr("style","display:none");
			Update_AllManagers_online();//更新营销人员在线状态
			G_filter_managers =G_managers;
			$("#mail_list_item_table").attr("class","mail_list_item item_less");
			$("#filter_list_up").hide();
			$("#list_navigation").show();
			$("#table_managerlist").show();
			LoadUserFirstTime(evid);//首次加载客户列表
			list_managers_state="true";
			$("#thmanagerschk").attr("style","");
			if(chkall_managers_states=="true"){
				$("#thmanagerschk").attr("checked",true);
			}else{
				$("#thmanagerschk").attr("checked",false);
			}
			break;
		case "list_customers":
			G_col=5;
			$("#thuserschk").attr("style","display:none");	
			Update_AllUsers_online();//更新客户在线状态		
			G_filter = G_users;
			$("#mail_list_item_table").attr("class","mail_list_item item_less");
			$("#filter_list_up").show();		
			$("#list_navigation").show();
			$("#table_userlist").show();
			LoadUserFirstTime(evid);//首次加载客户列表
			list_customers_state="true";
			if(chkall_users_states=="true"){
				$("#thuserschk").attr("checked",true);
			}else{
				$("#thuserschk").attr("checked",false);
			}		
			break;
		case "list_selected":
			G_col=8;
			$("#thselectechk").attr("style","display:none");
			$("#mail_list_item_table").attr("class","mail_list_item item_less");
			$("#filter_list_up").hide();
			$("#list_navigation").show();
			$("#table_selectedlist").show();
			Update_AllBrokers_online();//更新投顾在线状态
			Update_AllManagers_online();//更新营销人员在线状态
			Update_AllUsers_online();//更新客户在线状态	
			LoadUserFirstTime(evid);//加载已选	
			list_selected_state="true";//加载客户列表状态—选中
			$("#thselectechk").attr("style","");
			$("#thselectechk").attr("checked",true);
			break;
	}
}

/*
*经纪人加载用户列表
*/
function LoadUserFirstTime(evid)
{	
	ilisttab = evid;//记录当前标签id
	switch (evid)
	{
//		case "list_groups":			
//			load_list_groups(G_filter_groupslable,evid);
//			break;
		case "list_borkers":
			if(list_borkers_state=="false"){
				changePinYin_states($("#pinyin_all"));
				load_list_show(G_filter_brokers,evid);
			}else{
				changePinYin($("#pinyin_all"),'ALL');
			}
				
			break;
		case "list_managers":
			if(list_managers_state=="false"){
				changePinYin_states($("#pinyin_all"));
				load_list_show(G_filter_managers,evid);
			}else{
				changePinYin($("#pinyin_all"),'ALL');
			}
			break;
		case "list_customers":
			if(list_customers_state=="false"){
				changePinYin_states($("#pinyin_all"));
				load_users(G_filter);
			}else{
				changePinYin($("#pinyin_all"),'ALL');
			}
			break;
		case "list_selected":
			if(list_selected_state=="false"){
				changePinYin_states($("#pinyin_all"));
				load_list_selected(evid);	
			}else{
				changePinYin($("#pinyin_all"),'ALL');
			}
			//changePinYin($("#"+evid),'Selected');
			break;
	}
}
/*
*加载分组列表
*/
function load_list_groups(users,evid){
	
	var sdlstring = "";		
	for (var i=0; users != null && i < users.length; i++)
	{
		sdlstring += '<tr><td width="22">';
		if(users[i].selectedStatus == 1){
			sdlstring += '<input type="checkbox" onclick="javascript:chgSender_list(this,\''+ evid +'\'); stopBubble(event);" userid="' + users[i].id + '" username="'+ users[i].nm +'" checked="checked"/></td><td>' + users[i].nm +'('+ users[i].num + '人)';
		}else{
			sdlstring += '<input type="checkbox" onclick="javascript:chgSender_list(this,\''+ evid +'\'); stopBubble(event);" userid="' + users[i].id + '" username="'+ users[i].nm +'"/></td><td>' + users[i].nm +'('+ users[i].num + '人)';
		}
			sdlstring += '</td></tr>'
	}
	$("#dl_"+ evid).html(sdlstring);
}

/*
*加载已选列表
*/
function load_list_selected(evid)
{
//	//	G_filter_groupslable=G_groupslable;
//	//从分组数组中过滤出已选对象
//	G_filter_groupslable = $.grep(G_groupslable,function(v){	
//		if(v.selectedStatus == 1){
//			return true;
//		}
//	});
	//从用户数组中过滤出已选对象
	G_filter = $.grep(G_users,function(v){	
		if(v.selectedStatus == 1){
			return true;
		}
	});
	G_filter_brokers = $.grep(G_brokers,function(v){	
		if(v.selectedStatus == 1){
			return true;
		}
	});
	G_filter_managers = $.grep(G_managers,function(v){	
		if(v.selectedStatus == 1){
			return true;
		}
	});
	
	G_selecteds=G_filter.concat(G_filter_brokers).concat(G_filter_managers);
	var shtml = [];
	var l_users = sortusers(G_selecteds);//用户数组排序
	var G_All_users=l_users;	
	cacheuser = G_All_users;
	cacheindex = cacheuser.length-1;

	for (var i=0;i<cacheuser.length;i++)
	{
	
		if(i%2==0){
			if(cacheuser[i].selectedStatus == 1){
				shtml.push('<dd style="width:25px;background:#fff;"><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'"  usertype="'+ cacheuser[i].type +'" onclick="javascript:chgSender_selected(this); stopBubble(event);" checked="checked" /></dd>');
			}else{
				shtml.push('<dd style="width:25px;background:#fff;"><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'" usertype="'+ cacheuser[i].type +'"  onclick="javascript:chgSender_selected(this); stopBubble(event);" /></dd>');
			}
			if(cacheuser[i].type =="group"){
				shtml.push('<dd style="width:43px;background:#fff;">&nbsp;&nbsp;-</dd>');
			}else if(cacheuser[i].ol == "0"){
				shtml.push('<dd style="width:43px;background:#fff;"><img src="img/people.gif" /></dd>');
			}else{
				shtml.push('<dd style="width:43px;background:#fff;"><img src="img/people_online.gif" /></dd>');
			}
			shtml.push('<dd class="ddtext over" style="width:55px;background:#fff;"title="'+ cacheuser[i].nm +'">'+ cacheuser[i].nm +'</dd>');
			shtml.push('<dd class="ddtext" style="width:50px;background:#fff;" style="padding-left:13px;">'+ cacheuser[i].interactLvl +'</dd>');
		}else{
			if(cacheuser[i].selectedStatus == 1){
				shtml.push('<dd style="width:25px;background:#E4F5FF;"><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'"  usertype="'+ cacheuser[i].type +'" onclick="javascript:chgSender_selected(this); stopBubble(event);" checked="checked" /></dd>');
			}else{
				shtml.push('<dd style="width:25px;background:#E4F5FF;"><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'" usertype="'+ cacheuser[i].type +'"  onclick="javascript:chgSender_selected(this); stopBubble(event);" /></dd>');
			}
			if(cacheuser[i].type =="group"){
				shtml.push('<dd style="width:43px;background:#E4F5FF;">&nbsp;&nbsp;-</dd>');
			}else if(cacheuser[i].ol == "0"){
				shtml.push('<dd style="width:43px;background:#E4F5FF;"><img src="img/people.gif" /></dd>');
			}else{
				shtml.push('<dd style="width:43px;background:#E4F5FF;"><img src="img/people_online.gif" /></dd>');
			}
			shtml.push('<dd class="ddtext over" style="width:55px;background:#E4F5FF;" title="'+ cacheuser[i].nm +'">'+ cacheuser[i].nm +'</dd>');
			shtml.push('<dd class="ddtext" style="width:50px;background:#E4F5FF;" style="padding-left:13px;">'+ cacheuser[i].interactLvl +'</dd>');
		}
	/*	shtml.push('<tr style="background:#fff;" onclick="javascript:checkboxeline(this);">');
		if(cacheuser[i].selectedStatus == 1)
		{
			shtml.push('<td><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'"  usertype="'+ cacheuser[i].type +'" onclick="javascript:chgSender_selected(this); stopBubble(event);" checked="checked" /></td>');
		}
		else
		{
			shtml.push('<td><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'" usertype="'+ cacheuser[i].type +'"  onclick="javascript:chgSender_selected(this); stopBubble(event);" /></td>');
		}
		if (cacheuser[i].ol == "0")
		{
			shtml.push('<td><img src="img/people.gif" /></td>');
		}
		else
		{
			shtml.push('<td><img src="img/people_online.gif" /></td>');
		}
		shtml.push('<td id="name'+ cacheuser[i].id +'">'+ cacheuser[i].nm +'</td>');
		shtml.push('<td style="padding-left:16px;" id="interact'+ cacheuser[i].id+'">'+ cacheuser[i].interactLvl +'</td>');
		shtml.push('</tr>');
		*/	
	}
	var html = shtml.join("");
	$("#dl_"+ evid).html(html);
//	$("#tbody_"+ evid +" tr:odd").css("background","#E4F5FF");	
//	$("#thselectechk").attr("style","");
}
function load_list_selected_pinyin(l_users, evid){	
	var shtml = [];
	var G_All_users = sortusers(l_users);//用户数组排序
	cacheuser = G_All_users;
	for (var i=0;i<cacheuser.length; i++)
	{
		if(i%2==0){
			if(cacheuser[i].selectedStatus == 1){
				shtml.push('<dd style="width:25px;background:#fff;"><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'"  usertype="'+ cacheuser[i].type +'" onclick="javascript:chgSender_selected(this); stopBubble(event);" checked="checked" /></dd>');
			}else{
				shtml.push('<dd style="width:25px;background:#fff;"><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'" usertype="'+ cacheuser[i].type +'"  onclick="javascript:chgSender_selected(this); stopBubble(event);" /></dd>');
			}
			if (cacheuser[i].ol == "0"){
				shtml.push('<dd style="width:43px;background:#fff;"><img src="img/people.gif" /></dd>');
			}else{
				shtml.push('<dd style="width:43px;background:#fff;"><img src="img/people_online.gif" /></dd>');
			}
			shtml.push('<dd class="ddtext over" style="width:55px;background:#fff;" title="'+ cacheuser[i].nm +'">'+ cacheuser[i].nm +'</dd>');
			shtml.push('<dd class="ddtext" style="width:50px;background:#fff;" style="padding-left:13px;">'+ cacheuser[i].interactLvl +'</dd>');
		}else{
			if(cacheuser[i].selectedStatus == 1){
				shtml.push('<dd style="width:25px;background:#E4F5FF;"><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'"  usertype="'+ cacheuser[i].type +'" onclick="javascript:chgSender_selected(this); stopBubble(event);" checked="checked" /></dd>');
			}else{
				shtml.push('<dd style="width:25px;background:#E4F5FF;"><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'" usertype="'+ cacheuser[i].type +'"  onclick="javascript:chgSender_selected(this); stopBubble(event);" /></dd>');
			}
			if (cacheuser[i].ol == "0"){
				shtml.push('<dd style="width:43px;background:#E4F5FF;"><img src="img/people.gif" /></dd>');
			}else{
				shtml.push('<dd style="width:43px;background:#E4F5FF;"><img src="img/people_online.gif" /></dd>');
			}
			shtml.push('<dd class="ddtext over" style="width:55px;background:#E4F5FF;" title="'+ cacheuser[i].nm +'">'+ cacheuser[i].nm +'</dd>');
			shtml.push('<dd class="ddtext" style="width:50px;background:#E4F5FF;" style="padding-left:13px;">'+ cacheuser[i].interactLvl +'</dd>');
		}	
	/*	shtml.push('<tr style="background:#fff;" onclick="javascript:checkboxeline(this);">');
		if(cacheuser[i].selectedStatus == 1)
		{
			shtml.push('<td><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'"  usertype="'+ cacheuser[i].type +'" onclick="javascript:chgSender_selected(this); stopBubble(event);" checked="checked" /></td>');
		}
		else
		{
			shtml.push('<td><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'" usertype="'+ cacheuser[i].type +'"  onclick="javascript:chgSender_selected(this); stopBubble(event);" /></td>');
		}
		if (cacheuser[i].ol == "0")
		{
			shtml.push('<td><img src="img/people.gif" /></td>');
		}
		else
		{
			shtml.push('<td><img src="img/people_online.gif" /></td>');
		}
		shtml.push('<td id="name'+ cacheuser[i].id +'">'+ cacheuser[i].nm +'</td>');
		shtml.push('<td style="padding-left:16px;" id="interact'+ cacheuser[i].id+'">'+ cacheuser[i].interactLvl +'</td>');
		shtml.push('</tr>');	
		*/
	}
	var html = shtml.join("");
	$("#dl_"+ evid).html(html);
}
/*
*加载经纪人和投顾列表
*/
function load_list_show(users,evid)
{
	var shtml = [];
	var l_users = sortusers(users);
	var l_users = users;
	cacheuser = l_users;
	if(cacheuser%2==0){
		changecolor=0;
	}else{
		changecolor=1;
	}
	for (var i=cacheuser.length-1; i >=0; i--)
	{
		if (i%2==changecolor){
			if(cacheuser[i].selectedStatus == 1)
			{
				shtml.push('<dd style="width:25px;background:#fff;"><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'" onclick="javascript:chgSender_list(this,\''+ evid +'\'); stopBubble(event);" checked="checked" /></dd>');
			}
			else
			{
				shtml.push('<dd style="width:25px;background:#fff;"><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'" onclick="javascript:chgSender_list(this,\''+ evid +'\'); stopBubble(event);" /></dd>');
			}
			if (cacheuser[i].ol == "0")
			{
				shtml.push('<dd style="width:43px;background:#fff;"><img src="img/people.gif" /></dd>');
			}
			else
			{
				shtml.push('<dd style="width:43px;background:#fff;"><img src="img/people_online.gif" /></dd>');
			}
			shtml.push('<dd class="ddtext" style="width:118px;background:#fff;" >'+ cacheuser[i].nm +'</dd>');
		}else{
			if(cacheuser[i].selectedStatus == 1)
			{
				shtml.push('<dd style="width:25px;background:#E4F5FF;"><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'" onclick="javascript:chgSender_list(this,\''+ evid +'\'); stopBubble(event);" checked="checked" /></dd>');
			}
			else
			{
				shtml.push('<dd style="width:25px;background:#E4F5FF;"><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'" onclick="javascript:chgSender_list(this,\''+ evid +'\'); stopBubble(event);" /></dd>');
			}
			if (cacheuser[i].ol == "0")
			{
				shtml.push('<dd style="width:43px;background:#E4F5FF;"><img src="img/people.gif" /></dd>');
			}
			else
			{
				shtml.push('<dd style="width:43px;background:#E4F5FF;"><img src="img/people_online.gif" /></dd>');
			}
			shtml.push('<dd class="ddtext" style="width:118px;background:#E4F5FF;" >'+ cacheuser[i].nm +'</dd>');
		}
	}
	var html = shtml.join("");
	$("#dl_"+ evid).html(html);
/*
	for (var i=cacheuser.length-1; i >=0; i--)
	{
		shtml.push('<tr style="background:#fff;" onclick="javascript:checkboxeline(this);">');
		if(cacheuser[i].selectedStatus == 1)
		{
			shtml.push('<td><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'" onclick="javascript:chgSender_list(this,\''+ evid +'\'); stopBubble(event);" checked="checked" /></td>');
		}
		else
		{
			shtml.push('<td><input id="chk'+ cacheuser[i].id +'" userid="' + cacheuser[i].id + '" type="checkbox" username="'+ cacheuser[i].nm +'" onclick="javascript:chgSender_list(this,\''+ evid +'\'); stopBubble(event);" /></td>');
		}
		if (cacheuser[i].ol == "0")
		{
			shtml.push('<td><img src="img/people.gif" /></td>');
		}
		else
		{
			shtml.push('<td><img src="img/people_online.gif" /></td>');
		}
		shtml.push('<td id="name'+ cacheuser[i].id +'">'+ cacheuser[i].nm +'</td>');
	//	shtml.push('<td style="padding-left:16px;" id="interact'+ cacheuser[i].id+'">'+ cacheuser[i].interactLvl +'</td>');
		shtml.push('</tr>');		
	}
	var html = shtml.join("");

	$("#tbody_"+ evid).html(html);
	$("#tbody_"+ evid +" tr:odd").css("background","#E4F5FF");	
	*/
}




/*
*勾选事件
*value:勾选对象；
*evid:当前分组；
*/
function chgSender_list(value,evid)
{
	var userid = $(value).attr("userid");
	switch(evid){
//		case "list_groups":
//			var user = $.grep(G_groupslable,function(g_user,i){return g_user.id == userid;});	
//			break;
		case "list_borkers":
			var user = $.grep(G_brokers,function(g_user,i){return g_user.id == userid;});	
			break;
		case "list_managers":
			var user = $.grep(G_managers,function(g_user,i){return g_user.id == userid;});
			break;
	}
	if(value.checked)
	{		
		user[0].selectedStatus = 1;
	}
	else
	{
		user[0].selectedStatus = 0;
	}
	var	 sendername = selectusers;
	sendername = $.trim(sendername).split(";");
	var sname = $(value).attr("userid");
	if (sendername != null)
	{
		if (value.checked)
		{
			if ($.inArray(sname,sendername) < 0)
			{
				sendername.push(sname);
			}
		}
		else
		{
			sendername = $.grep(sendername,function(val,key){return val != sname;});
		}
		sendername = $.grep(sendername,function(val,key){return val != "";});
		selectusers=sendername.join(";");
	}
	else
	{
		selectusers=sname;
	}
}
/*
*按照首字母筛选用户列表根据分组标签
*/
function GetUserFilter()
{
	switch (ilisttab){
		case "list_customers":			
			G_filter = $.grep(G_users,function(v){
				return filterPinyin(pinyin,v);
			});
			load_users(G_filter);
			UserFilterImgStates();
		//	hideDiv('popSift');
			break;
		case "list_borkers":
			G_filter_brokers = $.grep(G_brokers,function(v){
				return filterPinyin(pinyin,v);
			});
			load_list_show(G_filter_brokers,"list_borkers");
			break;
		case "list_managers":
			G_filter_managers = $.grep(G_managers,function(v){
				return filterPinyin(pinyin,v);
			});
			load_list_show(G_filter_managers,"list_managers");		
			break;
		case "list_selected":
			if(pinyin=="ALL"){
				load_list_selected("list_selected");
			}else{
				G_filter_selecteds = $.grep(G_selecteds,function(v){
					return filterPinyin(pinyin,v);
				});
				load_list_selected_pinyin(G_filter_selecteds,"list_selected");		
			}
			break;
	}
}

/*
*已选勾选事件chgSender_selected
*/

function chgSender_selected(value)
{
	var userid = $(value).attr("userid");
	var usertype=$(value).attr("usertype");
	switch(usertype){
//		case "group":
//			var user = $.grep(G_groupslable,function(g_user,i){return g_user.id == userid;});	
//			break;
		case "customer":
			var user = $.grep(G_users,function(g_user,i){return g_user.id == userid;});	
			break;
		case "broker":
			var user = $.grep(G_brokers,function(g_user,i){return g_user.id == userid;});	
			break;
		case "manager":
			var user = $.grep(G_managers,function(g_user,i){return g_user.id == userid;});
			break;
	}
	if(value.checked)
	{		
		user[0].selectedStatus = 1;
	}
	else
	{
		user[0].selectedStatus = 0;
	}

	var txtsenderid = "#txtSender";
	var sendername = $(txtsenderid).val();
	sendername = $.trim(sendername).split(";");
	var sname = $(value).attr("username");
	if (sendername != null)
	{
		if (value.checked)
		{
			if ($.inArray(sname,sendername) < 0)
			{
				sendername.push(sname);
			}
		}
		else
		{
			sendername = $.grep(sendername,function(val,key){return val != sname;});
		}
		sendername = $.grep(sendername,function(val,key){return val != "";});
		selectusers=sendername.join(";");
	}
	else
	{
		selectusers=sname;
	}
}
/*
*用户列表勾选（全选）
*/
function allsender(obj,evid)
{	
	var user=[];
	var users = [];
	var usertype="";
	var sendername = ";"+selectusers;
	if(obj.checked)
	{
		$("#"+evid).find("input").each(function(index,value){
			value.checked = true;	
			usertype=$(value).attr("usertype");	
			if (sendername.indexOf(";"+value.userid+";") < 0)
			{		
				users.push(value.userid);
				userid = value.userid;
				switch(evid){
		//		case "tbody_list_groups":
		//			var user = $.grep(G_groupslable,function(g_user,i){return g_user.id == userid;});	
		//			break;
				case "tbuserlist":
					chkall_users_states="true";	
					G_chkalls[3]=true;
					user[0] = G_users_hash[userid];
				//	var user = $.grep(G_users,function(g_user,i){return g_user.id == userid;});	
					break;
				case "dl_list_borkers":
					chkall_brokers_states="true";
					G_chkalls[1]=true;
					user[0] = G_brokers_hash[userid];
				//	var user = $.grep(G_brokers,function(g_user,i){return g_user.id == userid;});	
					break;
				case "dl_list_managers":
					chkall_managers_states="true";
					G_chkalls[1]=true;
					user[0] = G_managers_hash[userid];
				//	var user = $.grep(G_managers,function(g_user,i){return g_user.id == userid;});
					break;
				case "dl_list_selected":										
					switch(usertype){
						case "group":
							user = $.grep(G_groupslable,function(g_user,i){return g_user.id == userid;});	
							break;
						case "customer":
							if(G_chkalls[3]==true){
								chkall_users_states="true";//记录用户全选状态
								$("#thuserschk").attr("checked",true);
							}else{
								chkall_users_states="false";//记录用户全选状态
								$("#thuserschk").attr("checked",false);
							}
							user[0] = G_users_hash[userid];
						//	user = $.grep(G_users,function(g_user,i){return g_user.id == userid;});	
							break;
						case "broker":
							if(G_chkalls[1]==true){
								chkall_brokers_states="true";//记录投顾全选状态	
								$("#thbrokerschk").attr("checked",true);
							}else{
								chkall_brokers_states="false";//记录投顾全选状态
								$("#thbrokerschk").attr("checked",false);
							}
							user[0] = G_brokers_hash[userid];
						//	user = $.grep(G_brokers,function(g_user,i){return g_user.id == userid;});	
							break;
						case "manager":
							if(G_chkalls[2]==true){
								chkall_managers_states="true";//记录营销全选状态
								$("#thmanagerschk").attr("checked",true);
							}else{
								chkall_managers_states="false";//记录营销全选状态
								$("#thmanagerschk").attr("checked",false);
							}
							user[0] = G_managers_hash[userid];
						//	user = $.grep(G_managers,function(g_user,i){return g_user.id == userid;});
							break;
					}
					break;	
				}			
				user[0].selectedStatus = 1;
			}		
		});
		if(sendername==";"){
			sendername="";
		}else{
			sendername=sendername.substring(1,sendername.length);
		}
		if (sendername!=""){
			selectusers=sendername + ";" + users.join(";");	
		}else{
			selectusers= users.join(";");	
		}
		
	}
	else
	{		
		if (sendername.substring(0,1) != ";")
		{
			sendername = ";" + sendername ;
		}
		if (sendername.substring(sendername.length -1) != ";")
		{
			sendername = sendername + ";";
		}
		$("#"+evid).find("input").each(function(index,value){
			value.checked = false;
			usertype=$(value).attr("usertype");	
			while (sendername.indexOf(";" + value.userid + ";") >=0)
			{
				sendername = sendername.replace(";" + value.userid + ";",";");
			}
			userid = value.userid;
			switch(evid){
		//		case "tbody_list_groups":
		//			var user = $.grep(G_groupslable,function(g_user,i){return g_user.id == userid;});	
		//			break;
				case "tbuserlist":
					chkall_users_states="false";//记录用户全选状态
					G_chkalls[3]=false;
					user[0] = G_users_hash[userid];
				//	var user = $.grep(G_users,function(g_user,i){return g_user.id == userid;});	
					break;
				case "dl_list_borkers":
					chkall_brokers_states="false";//记录投顾全选状态
					G_chkalls[1]=false;
					user[0] = G_brokers_hash[userid];
					//var user = $.grep(G_brokers,function(g_user,i){return g_user.id == userid;});	
					break;
				case "dl_list_managers":
					chkall_managers_states="false";//记录营销全选状态
					G_chkalls[2]=false;
					user[0] = G_managers_hash[userid];
				//	var user = $.grep(G_managers,function(g_user,i){return g_user.id == userid;});
					break;
				case "dl_list_selected":								
					switch(usertype){
						case "group":
							user = $.grep(G_groupslable,function(g_user,i){return g_user.id == userid;});	
							break;
						case "customer":
							if(G_chkalls[3]==true){
								chkall_users_states="false";//记录用户全选状态								
								$("#thuserschk").attr("checked",false);
							}else{
								chkall_users_states="false";//记录用户全选状态							
								$("#thuserschk").attr("checked",false);
							}
							user[0] = G_users_hash[userid];
						//	user = $.grep(G_users,function(g_user,i){return g_user.id == userid;});	
							break;
						case "broker":
							if(G_chkalls[1]==true){
								chkall_brokers_states="false";//记录投顾全选状态
								$("#thbrokerschk").attr("checked",false);								
							}else{
								chkall_brokers_states="false";//记录投顾全选状态
								$("#thbrokerschk").attr("checked",false);
							}
							user[0] = G_brokers_hash[userid];
						//	user = $.grep(G_brokers,function(g_user,i){return g_user.id == userid;});	
							break;
						case "manager":
							if(G_chkalls[2]==true){
								chkall_managers_states="false";//记录营销全选状态
								$("#thmanagerschk").attr("checked",false);
							}else{
								chkall_managers_states="false";//记录营销全选状态
								$("#thmanagerschk").attr("checked",false);
							}
							user[0] = G_managers_hash[userid];
						//	user = $.grep(G_managers,function(g_user,i){return g_user.id == userid;});
							break;
					}
					break;
			}		
			user[0].selectedStatus = 0;
		});
		if (sendername.substring(0,1) == ";")
		{
			sendername = sendername.substring(1,sendername.length);
		}
		if (sendername.substring(sendername.length -1) == ";")
		{
			sendername = sendername.substring(0,sendername.length - 1);
		}
		selectusers=sendername;
	}
}
/*
*分组排序
*/
function orderlist(col)
{
	G_col = col;
	G_descs[G_col] = !G_descs[G_col];
	switch(ilisttab){
		case "list_customers":		
			load_users(G_filter);		
			break;
		case "list_borkers":
			load_list_show(G_filter_brokers,"list_borkers");
			break;
		case "list_managers":		
			load_list_show(G_filter_managers,"list_managers");		
			break;	
		case "list_selected":
			load_list_selected("list_selected");
			break;
	}
}

/*
*分组列表排序
*/
function sortusers(users)
{
	if(typeof(users.length)=="undefined"){	
		return;
	}
	for(var i=0 ;i<G_descs.length;i++)
	{
		$("#span_do_" + i).text("");
	}
	var l_users;
	switch (G_col)
	{
	//互动度
	case 7:
	case 10:
		if (G_descs[G_col])
		{
			$("#span_do_" + G_col).text("↑");
		}
		else
		{
			$("#span_do_" + G_col).text("↓");
		}
		l_users = users.sort(function(a,b) {
			if (G_descs[G_col])
			{
				if(parseFloat(a.interactLvl) > parseFloat(b.interactLvl)) return -1;
				if(parseFloat(a.interactLvl) < parseFloat(b.interactLvl)) return 1;
				return 0;
			}
			else
			{
				if(parseFloat(a.interactLvl) < parseFloat(b.interactLvl)) return -1;
				if(parseFloat(a.interactLvl) > parseFloat(b.interactLvl)) return 1;
				return 0;
			}
		})
		break;
	//姓名
	case 2:
	case 4:
	case 6:
	case 9:
		if (G_descs[G_col])
		{
			$("#span_do_" + G_col).text("↑");
		}
		else
		{
			$("#span_do_" + G_col).text("↓");
		}
		l_users = users.sort(function(a,b) {		
			if (G_descs[G_col])
			{
				if(a.qp > b.qp) return -1;
				if(a.qp < b.qp) return 1;
				return 0;
			}
			else
			{
				if(a.qp < b.qp) return -1;
				if(a.qp > b.qp) return 1;
				return 0;
			}

		})
	break;
	case 1:
	case 3:
			if (G_descs[G_col])
		{
			$("#span_do_" + G_col).text("↑");
		}
		else
		{
			$("#span_do_" + G_col).text("↓");
		}
		l_users = users.sort(function(a,b) {
			if (G_descs[G_col])
			{
				if(a.ol > b.ol) return -1;
				if(a.ol < b.ol) return 1;
				return 0;
			}
			else
			{
				if(a.ol < b.ol) return -1;
				if(a.ol > b.ol) return 1;
				return 0;
			}
		})
		break;
	case 5:
	case 8:
	default:
		if (G_descs[G_col])
		{
			$("#span_do_" + G_col).text("↑");
		}
		else
		{
			$("#span_do_" + G_col).text("↓");
		}
		l_users = users.sort(function(a,b) {
			if (G_descs[G_col]){
				if(parseFloat(a.interactLvl) > parseFloat(b.interactLvl)) return -1;
				if(parseFloat(a.interactLvl) < parseFloat(b.interactLvl)) return 1;
				return 0;
			}else
			{
				if(parseFloat(a.interactLvl) < parseFloat(b.interactLvl)) return -1;
				if(parseFloat(a.interactLvl) > parseFloat(b.interactLvl)) return 1;
				return 0;
			}
		})
		l_users = users.sort(function(a,b) {
			if (G_descs[G_col]){
				if(a.ol > b.ol) return -1;
				if(a.ol < b.ol) return 1;
				return 0;
			}else{
				if(a.ol < b.ol) return -1;
				if(a.ol > b.ol) return 1;
				return 0;
			}
		})
	break;
	}
	return l_users;
}
/*
*发送邮件人员帐号与名称转换
*/
function getsender(attr)
{
	var txtsenderid = "#txtSender";
	var Senders = ";";
	var yesno = -1;
	var tmpname="";
	var sendername = $.trim($(txtsenderid).val()).split(";");
	$(sendername).each(function(index){
		var name = $.trim(sendername[index]);
		if (name =="")
		{
		}
		else
		{
			var correctName = false;
			//分组
			if(name=="[全部投顾]"){
				for (var i=0; G_brokers != null && i < G_brokers.length ; i++)
				{
					yesno = Senders.indexOf(";" + G_brokers[i].id + ";");				
					if(yesno < 0)
					{
						Senders += G_brokers[i].id + ";";
					}
				}
				return true;
			}else if(name=="[全部客户经理]"){
				for (var i=0; G_managers != null && i < G_managers.length ; i++)
				{
					yesno = Senders.indexOf(";" + G_managers[i].id + ";");				
					if(yesno < 0)
					{
						Senders += G_managers[i].id + ";";
					}
				}
				return true;
			}else if(name=="[全部股民]"){
				for (var i=0; G_users != null && i < G_users.length ; i++)
				{
					yesno = Senders.indexOf(";" + G_users[i].id + ";");				
					if(yesno < 0)
					{
						Senders += G_users[i].id+ ";";
					}
				}
				return true;
//			}else if((name.indexOf("[")>-1) && (name.indexOf("]")>-1)){
//				tmpname=name.replace("[","").replace("]","");
//				
//				for (var i=0; G_groupslable != null && i < G_groupslable.length ; i++){
//					if (G_groupslable[i].nm == tmpname){
//						for( var j=0;j< G_groupslable[i].num;j++){
//							yesno = Senders.indexOf(";" + G_groupslable[i]["users"][j].id + ";");				
//							if(yesno < 0)
//							{
//								Senders += G_groupslable[i]["users"][j].id+ ";";
//							}
//						}
//					}
//				}
//				return true;
			}
			//投顾
			for (var i=0; G_brokers != null && i < G_brokers.length ; i++)
			{
				if (G_brokers[i].nm == name)
				{
					yesno = Senders.indexOf(";" + G_brokers[i][attr] + ";");				
					if(yesno < 0)
					{
						Senders += G_brokers[i][attr] + ";";
					}
					correctName = true;
					break;
				}
			}
			//营销
			for (var i=0; G_managers != null && i < G_managers.length ; i++)
			{
				if (G_managers[i].nm == name)
				{
					yesno = Senders.indexOf(";" + G_managers[i][attr] + ";");				
					if(yesno < 0)
					{
						Senders += G_managers[i][attr] + ";";
					}
					correctName = true;
					break;
				}
			}
			//股民
			for (var i=0; G_users != null && i < G_users.length ; i++)
			{
				if (G_users[i].nm == name)
				{
					yesno = Senders.indexOf(";" + G_users[i][attr] + ";");				
					if(yesno < 0)
					{
						Senders += G_users[i][attr] + ";";
					}
					correctName = true;
					break;
				}
			}
			if(correctName == false)
			{
				yesno = Senders.indexOf(name);
				if(yesno < 0)
				{
					Senders += name + ";";
				}
			}
		}
	});
	if (Senders.length >1 && Senders.substring(Senders.length - 1) == ";")
	{
		Senders = Senders.substring(1,Senders.length - 1);
	}
	return Senders;
}
/*
*
*/
function changePinYin(ev,pinyinFilter)
{
	pinyin = pinyinFilter;
	changePinYin_states(ev)
	GetUserFilter();
}
/*
*修改标签样式切换
*/
function changePinYin_states(ev)
{

	if ($(ev).hasClass("mail_list_navigation_span_sel"))
		return;
	$(ev).parent().parent().find("li span.mail_list_navigation_span_sel").toggleClass("mail_list_navigation_span_nosel").toggleClass("mail_list_navigation_span_sel");
	$(ev).toggleClass("mail_list_navigation_span_nosel").toggleClass("mail_list_navigation_span_sel");

}
