// JavaScript Document
var pinyin = "ALL"; //当前用户列表所选的首字母标签
var itab = "-1";
var NewEmailSeq = "";
var sourceSeq = "";
var sourceType = "";
var sourceFrom="";
var sendMK = ""; //当前市场
var sendCODE = ""; //当前商品
var sendprocess = null;
var sendMailTimeState="false";//发送邮件计时是否启用
var loadBrokerRightState="false";//长期权限、我的权限是否已加载完成
var loadBrokerTrialRightState="false";//试用权限是否加载完成
var	loadBrokerShortRightState="false";//短期权限是否加载完成
var loadFilterState="false";//筛选是否已加载完成
var G_sFilter = "";
var replaceHtml = '<B name="#replace#"></B>';
var default_content="";
var isButtonClick = false;
var g_content = ""; //文本内容
var g_sendlogtype = "";
var g_sendlogtxt = "";
var g_senders = [];
var g_gid = "";
var ifrmwrEditor; //富文本编辑框的引用
var mytimer = null;
var closetimer = null;
var total_imgsize = 0;
var total_filesize = 0;
var attachfiles = [];
var html_vroom = null;		// lujh 2013-3

var tas;//普通邮件智能键盘对象
var tgc;//黄金眼智能键盘对象
var ts;//收件人智能键盘
var G_col = 0;//分组
//var G_descs = [false,true,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="";//记录当前分组标签id
var G_descs= [true,false,true,false,true,false,true,true,false,true,true];
var mytime_showsum=null;
//0：分组名称：1：投顾状态 2：投顾姓名 3：营销状态 4：营销姓名 5：客户在线状态 6:客户姓名 7：客户互动度 8：已选在线状态 9:已选姓名 10：已选互动度
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;//为了统一隔行换色
var G_user_do_states="";//记录用户列表默认排序内容
var G_user_pinyin_states="";//记录用户列表选择的拼音分组
var proc_mkcode_str="";//产品中心用股票格式   浦发银行(SH600000)
	
/*-------------------------------------------------------经纪人列表结束----------------------------------*/


function operatemail(values) //客户端回调发邮件页面公共JS
{	
	params = values.replace(/%26/g,"&");
	var stype = getparamter(params,"type");	
	var sOldSeq = "";
	var value = getparamter(params,"page");
	switch (value) //判断是否需要页面跳转
	{
	case "maillist.htm":
		window.location = "maillist.htm?" + params;
		break;
	case "writemail.htm":
		window.location = "writemail.htm?" + params;
		break;
	}
	cleartab2();
	var stab = getparamter(params,"tab");
	if (stab == null)
	{
		stab = "0";
	}
	changeTab(stab,"btn");
	if(stype==2.5)//转发
	{		
		cleartab0();
		cleartab1();
		cleartab2();
		cleartab3();
		clearFilter();
		var sOldSeq = getparamter(params,"seq");
		NewEmailSeq = transpondReadMail(sOldSeq);
		ifrmwrEditor.setContent(g_content);
		G_Parent.GLOBAL_Seq = NewEmailSeq;
		reloadattachs();
		if (attachfiles.length >0)
		{
			$("#contentarea").attr("style","height:250px; margin-top:20px;");
			ifrmwrEditor.setHeight(200);
			ifrmwrEditor.body.style.height = "200px";
		}
		else
		{
			$("#contentarea").attr("style","height:270px;");
			ifrmwrEditor.setHeight(220);
			ifrmwrEditor.body.style.height = "220px";
		}
		getAttach(NewEmailSeq);
		$("#tab_button_1").removeAttr("onclick");
		$("#tab_button_3").removeAttr("onclick");
		$("#tab_button_1").attr("class","mail_system_11");
		$("#tab_button_3").attr("class","mail_system_33");
			
	}
	else if (stype == 2) //回复
	{
		cleartab0();
		cleartab1();
		cleartab2();
		cleartab3();
		clearFilter();
		var sOldSeq = getparamter(params,"seq");
		ReadMail(sOldSeq);
		ifrmwrEditor.execCommand('inserthtml',g_content);
		NewEmailSeq = NewMail();
		G_Parent.GLOBAL_Seq = NewEmailSeq;
	}
	else 
	{
		if (getparamter(values,"seq") != null) //反向添加附件
		{
			changetab("0","btn");
			G_Parent.GLOBAL_Seq = getparamter(values,"seq");
			NewEmailSeq = G_Parent.GLOBAL_Seq;
			stype = 0;
			getAttach(NewEmailSeq);
			AddAttach();
		}
		else (getparamter(params,"usernamekey") != null) //从平台过来的调用，写邮件给某些人
		{
			cleartab0();
			cleartab1();
			cleartab2();
			cleartab3();
			clearFilter();
			attachfiles = [];
			reloadattachs();
			stype = 0;
			NewEmailSeq = NewMail()
			G_Parent.GLOBAL_Seq = NewEmailSeq;
			var key = getparamter(values,"usernamekey");
			var odata = client_data_load(key,"0");
			if (odata != null)
			{
				if(odata.dValue !="")
				{
					$("#txtSender").val(odata.dValue+";");
				}
			}
			senderMK = getparamter(values,"mk"); //盯盘过来的市场代码
			senderCODE = getparamter(values,"code"); //盯盘过来的商品代码
			if(senderMK != undefined &&senderCODE != undefined && senderMK!="" && senderCODE!="")
			{
				senderMK=senderMK.toUpperCase();
				$("#txtGoldCode").val(senderMK+senderCODE);
				$("#txtGoldCode").attr("mk",senderMK);
				var tmpCodeName=ExistCode(senderMK,senderCODE);		
				if (tmpCodeName != "-1")
				{
					$("#txtTitle").val("黄金眼主力数据赋权 代码：" + senderCODE + tmpCodeName);
				}
			}
		}
	}
	changelist('list_groups');//分组标签默认显示
	SynchroniseSender($("#txtSender").val(),false);
	
		if ($("#txtSender").val() == "发送多人时请以英文分号分隔")
		{
			$("#txtSender").css("color","gray");
		}
		else
		{
			$("#txtSender").css("color","black");
		}


	if (($("#txtSender").val() != "发送多人时请以英文分号分隔") && ($("#txtSender").val() != ""))
	{
		$("#tbuserlist").find("input").each(function(){
			if (this.checked == true)
			{
				$(".mail_list_navigation ul li span")[0].click();
				return;
			}
		});
	}
	getsumnum();
}

//清楚用户列表删选内容
function clearFilter()
{
	$("#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});
	G_filter = G_users;
	pinyin = "";
	$(".mail_list_top span").removeClass("mail_list_pop_span");
	hideDiv('popSift');
}

//发送超时显示消息
function sendfail()
{
	clearTimeout(sendprocess);
	sendMailMessage("-2");//发送失败（超时）
}


//清除普通邮件输入内容
function cleartab0()
{
	$("#txtSender").val("发送多人时请以英文分号分隔");
	$("#txtTitle").val("");
	ifrmwrEditor.setContent(default_content);//设置富文本为默认值
}
//清除黄金眼输入内容
function cleartab1()
{
	$("#txtSender").val("发送多人时请以英文分号分隔");
	$("#txtTitle").val("");
	ifrmwrEditor.setContent(default_content);//设置富文本为默认值
}
//清除长期权限输入内容
function cleartab2()
{
	$("#txtSender").val("发送多人时请以英文分号分隔");
	$("#txtTitle").val("");
	$("#tblongright tr").each(function()
	{
		$(this).children("td:eq(0)").find("input").attr("checked",false);
		$(this).children("td:eq(2)").find("input").val("");
	})
	ifrmwrEditor.setContent(default_content);//设置富文本为默认值
}
//清除产品试用输入内容
function cleartab3()
{
	$("#txtSender").val("发送多人时请以英文分号分隔");
	$("#txtTitle").val("");
	ifrmwrEditor.setContent(default_content);//设置富文本为默认值
}

//弹出发送邮件等待提示信息
function popupDiv(div_id) 
{		
	$("#" + div_id).css({ 
    	position: "absolute", 
    	left: ($(window).width() - $("#" + div_id).outerWidth())/2, 
    	top: ($(window).height() - $("#" + div_id).outerHeight())/2 
    });	
	$("#dvWait").hide();
	$("#" + div_id).show();
	if(div_id=="dvWait")
	{	
		$("#dvWait_bg").show();		
		sendMailMessage("1");
		mytimer = setTimeout("showtime(1)",500); 
	}
}

function closeMe()
{
	clearTimeout(closetimer);
	closeWindow();
}

//发送邮件成功失败提示
function sendMailMessage(msgType)
{
	switch(msgType)
	{
		case"1"://发送邮件开始
			sendMailTimeState="true";
			$("#dvWait_1").show();	
			$("#dvWait_2").hide();	
			$("#dvWait_3").hide();	
			$("#dvWait_ok").hide();	
			break;
		case"2"://发送邮件成功
			sendMailTimeState="false";
			$("#dvWait_1").hide();	
			$("#dvWait_2").show();	
			$("#dvWait_3").hide();	
			$("#dvWait_ok").hide();
			if (itab == "1")
			{
				var rtn = setRightShort(g_senders.join(","),$("#GoldattstockSelect").attr("optionvlue"),g_gid,proc_mkcode_str).replace(/\r\n/g,"");
				if (rtn != "1")
				{
					alert("邮件发送成功,但短期权限分配操作失败!(" + rtn + ")");
				}
			}
			if (g_sendlogtype == "A4")
			{
				$.each(g_senders,function(i,txt){
					switch (itab)
					{
					case "0":
						write_log("A4",g_gid + "," +txt+",0");
					break;
					case "1":
						write_log("A4",g_gid + "," +txt+",4");
					break;
					case "2":
						write_log("A4",g_gid + "," +txt+",3");
					break;
					case "3":
						write_log("A4",g_gid + "," +txt+",6");
					break;
					default:
						write_log("A4",g_gid + "," +txt+",0");
					break;
					}
				});						
			}
			else
			{
					write_log(g_sendlogtype,g_gid + g_sendlogtxt);
			}
			closetimer = setTimeout("closeMe()",300); 
			break;
		case"-1"://发送邮件失败
			sendMailTimeState="false";
			$("#dvWait_1").hide();	
			$("#dvWait_2").hide();	
			$("#dvWait_3").show();	
			$("#dvWait_errMsg").text("邮件发送失败!");		
			$("#dvWait_ok").show();	
			break;	
		case"-2"://发送邮件失败
			sendMailTimeState="false";
			$("#dvWait_1").hide();	
			$("#dvWait_2").hide();	
			$("#dvWait_3").show();	
			$("#dvWait_errMsg").text("连接超时，邮件发送失败!");		
			$("#dvWait_ok").show();	
			break;
		case"-3"://发送邮件失败
			sendMailTimeState="false";
			$("#dvWait_1").hide();	
			$("#dvWait_2").hide();	
			$("#dvWait_3").show();	
			$("#dvWait_errMsg").text("系统错误，邮件发送失败!");		
			$("#dvWait_ok").show();	
			break;
		case"-4"://发送邮件超过8K
			sendMailTimeState="false";
			$("#dvWait_1").hide();	
			$("#dvWait_2").hide();	
			$("#dvWait_3").show();	
			$("#dvWait_errMsg").text("邮件正文或附件太大!");		
			$("#dvWait_ok").show();	
			break;
	}
}

//邮件提示计时
function  showtime(time)
{
	clearTimeout(mytimer);
	if(	sendMailTimeState=="true")
	{
		$("#dvWait_time").text(time);
		time=time+1;
		mytimer = setTimeout("showtime("+time+")",1000); 
	}
}

//隐藏弹出层
function hideDiv(div_id)
{ 
	$("#" + div_id).hide();
	if(div_id=="dvWait")
	{	
		$("#dvWait_bg").hide();
	}
}


//标签切换 0普通邮件、1短期权限、2长期权限、3试用权限、
function changeTab(tabid,source)
{
	if (tabid == itab)
	{
		return;
	}
	if(tabid=="0" && source == "btn")//普通消息
	{
		if (attachfiles.length >0)
		{
			$("#contentarea").attr("style","height:250px; margin-top:20px;");
			ifrmwrEditor.setHeight(200);
			ifrmwrEditor.body.style.height = "200px";
		}
		else
		{
			$("#contentarea").attr("style","height:270px;");
			ifrmwrEditor.setHeight(220);
			ifrmwrEditor.body.style.height = "220px";
		}
	}
	if(tabid=="1" && source == "btn")//黄金眼短期权限
	{
		$("#contentarea").attr("style","height:270px;");
		ifrmwrEditor.setHeight(220);
		ifrmwrEditor.body.style.height = "220px";
		load_brokerShortRight();
	}
	if(tabid=="2" && source == "btn")//加载长期权限
	{	
		$("#contentarea").attr("style","height:270px;");
		ifrmwrEditor.setHeight(220);
		ifrmwrEditor.body.style.height = "220px";
		load_brokerRight();	
	}
	if(tabid=="3" && source == "btn")//加载试用权限
	{			
		$("#contentarea").attr("style","height:270px;");
		ifrmwrEditor.setHeight(220);
		ifrmwrEditor.body.style.height = "220px";
		load_brokerTrialRight();	
	}
	
	var ioldtab = itab;
	itab = tabid;
	for(var i=0; i < 4; i++)
	{
		if(i.toString() == tabid.toString())
		{			
			$("#content"+i).show();
			$("#tab_button_"+i.toString()).removeClass("mail_system_" + i.toString());
			$("#tab_button_"+i.toString()).addClass("mail_system_" + i.toString() + "_action");
		}
		else
		{
			$("#content"+i.toString()).hide();
			$("#tab_button_"+i.toString()).removeClass("mail_system_" + i.toString() + "_action");
			$("#tab_button_"+i.toString()).addClass("mail_system_" + i.toString());
		}
	}
	$('#divattstock').hide();
	$('#divstockcode').hide();
	divattstockclose();
	ifrmwrEditor.setContent(default_content);//设置富文本为默认值
}
//利用JavaScript来获取HTML标签字符串，并去掉标签。
function strip(html)   
{   
   var tmp = document.createElement("DIV");   
   tmp.innerHTML = html; 
   $(tmp).find("input").each(function(){
	   $(this).attr("disabled", true); 
   });
   return  tmp.innerHTML;
}   

//回复邮件读取原邮件
function ReadMail(seq)
{
	var text = GetMail(seq);
	var iFirstContent = text.indexOf("<content><![CDATA[");
	var iLastContent = text.lastIndexOf("]]></content>");
	var sbody = strip(text.substring(iFirstContent + 18,iLastContent));
	text = text.substring(0,iFirstContent) + "<content></content>" + text.substring(iLastContent + 13,text.length);
	var xml = ql_xml_stringtoxml(text.replace(/\r/g, ""));	
	var sfrom = $($(xml).find("from")[0]).text();	
	sourceFrom = sfrom;
	var sfromName = sfrom;	
	var tmpsfromName=$($(xml).find("from")[0]).attr("name");
	if(tmpsfromName != undefined && tmpsfromName != "")
	{
		sfromName=tmpsfromName;
	}

	var sto = $($(xml).find("to")[0]).text();
	var stimestamp = $($(xml).find("mail")[0]).attr("timestamp");
	sourceSeq = $($(xml).find("mail")[0]).attr("sourceseq");
	sourceType = $($(xml).find("type")[0]).attr("no");	
	var stitle = decodeString($($(xml).find("title")[0]).text());
	//附件过滤
	sbody=checkattachstrip(sbody);//过滤附件内容
	sbody = checkimgstrip(sbody);
	sbody = checkoldimgstrip(sbody);
	$("#txtSender").val(sfromName+";");
	$("#txtTitle").val("回复:"+stitle);
	
	//回复不再带有原邮件内容
//	sTmp = "<br /><br /><div>---------------------------------------------------<br />";
//	sTmp +="发件人: "+sfromName+"<br>";
//	sTmp +="发送时间: "+stimestamp+"<br>";
//	sTmp +="收件人: "+sto+"<br>";
//	sTmp +="主题: "+html_encode(stitle)+"<br>";
//	sbody = sTmp + sbody + "</div>";
	g_content = "";
}
/*
*利用JavaScript来获取div标签字符串，并替换附件。
*/
function checkattachstrip(html)
{
   var tmp = document.createElement("DIV");   
   var imgsize = 0;
   tmp.innerHTML = html; 
   $(tmp).find("div").each(function(){   	   
	   if(typeof( $(this).attr("attach")) != "undefined")
   	   {
		   if ($(this).attr("attach").length >0)
		   {
		   	   $(this).attr("attach","");
		   }
   	   }
   });
   return  tmp.innerHTML;
}
//转发读取邮件
function transpondReadMail(seq)
{
	var text = ForwardMail(seq);
	var iFirstContent = text.indexOf("<content><![CDATA[");
	var iLastContent = text.lastIndexOf("]]></content>");
	var sbody = sbody = text.substring(iFirstContent + 18,iLastContent);
	attachfiles = getattachfile(sbody);
	text = text.substring(0,iFirstContent) + "<content></content>" + text.substring(iLastContent + 13,text.length);
	var xml = ql_xml_stringtoxml(text.replace(/\r/g, ""));	
	var sfrom = $($(xml).find("from")[0]).text();	
	sourceFrom = sfrom;
	var sfromName = sfrom;
	var tmpsfromName=$($(xml).find("from")[0]).attr("name");
	if(tmpsfromName != undefined && tmpsfromName != "")
	{
		sfromName=tmpsfromName;
	}

	var sto = $($(xml).find("to")[0]).text();
	var stimestamp = $($(xml).find("mail")[0]).attr("timestamp");
	var myseq = $($(xml).find("mail")[0]).attr("seq");
	sourceSeq = "";
	sourceType = "";
	sbody=checkattachstrip(sbody);//过滤附件内容
	var stitle = decodeString($($(xml).find("title")[0]).text());
	$("#txtTitle").val("转发:"+stitle);
	sTmp = "<br /><br /><div>---------------------------------------------------<br />";
	sbody=sbody.replace(/font_somber/g,"");//替换掉标题字体颜色样式
	sbody = checkimgstrip(sbody);
	sbody = checkoldimgstrip(sbody);
	sTmp +="发件人: "+sfromName+"<br>";
	sTmp +="发送时间: "+stimestamp+"<br>";
//	sTmp +="收件人: "+sto+"<br>";
	sTmp +="主题: "+html_encode(stitle)+"<br>";
	sbody = sTmp + sbody + "</div>";
	g_content = sbody + "</div>";
	return myseq;
}
//兼容老版本图片
function checkoldimgstrip(html)   
{   
   var tmp = document.createElement("DIV");   
   tmp.innerHTML = html; 
   $(tmp).find("img").each(function(){
   	   if(typeof( $(this).attr("filename")) == "undefined"  && typeof( $(this).attr("data_ue_src")) == "undefined")
	   {
			var OLDATTACHSERVICES = OLDATTACHSERVICE();
			for(var i=0 ;i< OLDATTACHSERVICES.length;i++)
			{
				$(this).attr("src",$(this).attr("src").replace(OLDATTACHSERVICES[i],G_DOWNLOADSERVICE()));
				$(this).attr("filename",$(this).attr("src").replace(OLDATTACHSERVICES[i],""));
			}
			OLDATTACHSERVICES = null;
	   }
   });
   return  tmp.innerHTML;
}  

function StockListClick(li)
{	
	sendCODE=$(li).attr("code");
	sendMK=$(li).attr("market");
	$(li).parent().children("li").css("background","").css("color","#767676");
	$(li).css("background","#85caff").css("color","#fff");
	$("#stockValue").val(sendMK + sendCODE);
}

function insertline()
{
	//$('#divattstock').hide();
	// lujh, 2013-3
	hide_allpopup();
	
	var lHtml= "";
	var CurrStock = getCurrStock();
	if (CurrStock != null && CurrStock != "")
	{
		var CurrStockinfo = CurrStock.split(",");
		sendMK = CurrStockinfo[0].toString();
		sendCODE = CurrStockinfo[1].toString();
	}
	var strList = getDrawlinestocklist();//市场,商品代码|市场,商品代码
	if (strList.length <= 0)
	{
		alert("系统未找到任何商品的画线操作，请先画线后再试！");
		return;
	}
	if(strList.length > 0)
	{
		var aTemp = strList.split("|");
		$("#stockValue").val("");
		$.each(aTemp,function(i,v){
			var aStock = v.split(",");
		var tmpCodeName=ExistCode(aStock[0],aStock[1]);
			lHtml += '<li onclick="StockListClick(this);" ondblclick="StockListClick(this);commitcode();" market="' + aStock[0] + '" code="'+ aStock[1] +'" stock="'+ (aStock[0]+aStock[1]) +'" style=" width:100px;background:';
			if ((aStock[0] == sendMK) && (aStock[1] == sendCODE))
			{
				$("#stockValue").val(aStock[0]+aStock[1]);
				lHtml += '#85caff;';
			}
			if(tmpCodeName!="-1")
			{
				lHtml += '"><span>'+ tmpCodeName +'('+ aStock[1] +')</span></li>';	
			}else{
				lHtml += '"><span>'+ aStock[1] +'</span></li>';	
			}
		
		});
	}
	$("#div_stocklist ul").html(lHtml);
	$("#divstockcode").show();
}

function commitcode()
{
	$('#divstockcode').hide();
	isButtonClick = true;
	if(AddMailAttach(NewEmailSeq,"3\r\n"+$("#stockValue").val()+",7") < 0)
	{
		alert("添加画线分析失败");
	}
}

function insertformula()
{
	//$('#divattstock').hide();
	//$('#divstockcode').hide();
	// lujh, 2013-3
	hide_allpopup();
	
	isButtonClick = true;
	if(AddMailAttach(NewEmailSeq,"4") < 0)
	{
		alert("添加技术指标失败");
	}
}

function insertcommpool()
{
	//$('#divattstock').hide();
	//$('#divstockcode').hide();
	// lujh, 2013-3
	hide_allpopup();
	
	isButtonClick = true;
	var data = AddMailAttach(NewEmailSeq,"2");
	if( data < 0)
	{
		alert("添加推荐版块失败");
	}
	else
	{
		isButtonClick = false;
	}
}

function showstock()
{
	if(tas !=null){
		tas.Clear();
	}
	//$('#divstockcode').hide();
	// lujh, 2013-3
	hide_allpopup();
	
	var CurrStock = getCurrStock();
	sendMK = "";
	sendCODE="";
	if (CurrStock != null && CurrStock != "")
	{
		var CurrStockinfo = CurrStock.split(",");
		sendMK = CurrStockinfo[0].toString();
		sendCODE = CurrStockinfo[1].toString();
	}
	$('#txtattstock').attr("mk",sendMK);
	$('#txtattstock').val(sendMK+sendCODE);
	isButtonClick = true;
	$('#divattstock').show();
	$('#txtattstock').focus();
}

function insertstock()
{
	if ($("#txtattstock").val() != "")
	{
	//	var data = AddMailAttach(NewEmailSeq,"1\r\n"+$("#txtattstock").attr("mk") + $("#txtattstock").val());
	var data = AddMailAttach(NewEmailSeq,"1\r\n"+ $("#txtattstock").val());
		if( data < 0)
		{
			alert("添加推荐个股失败");
			$('#txtattstock').focus();
		}
		else if (data > 0)
		{
			isButtonClick = false;
			$('#divattstock').hide();
		}
		else
		{
			$('#txtattstock').focus();
		}
	}
	else
	{
		alert("请输入股票代码");
		$('#txtattstock').focus();
	}
}

function AddAttach()
{
	var xml =ql_xml_stringtoxml("<xml>" + G_Parent.GLOBAL_Attach.replace(/\r/g, "") + "</xml>");
	var arr_attach = $(xml).find("attach");
	var type = $(arr_attach[arr_attach.length-1]).attr("type");
	var desc = $(arr_attach[arr_attach.length-1]).find("desc").text();	
	var inputValue="自定义";
	var mytype="0";
	switch(type)
	{
		case "1":		
			var tmpCodeName = ExistCode($("#txtattstock").val().substring(0,2),$("#txtattstock").val().substring(2,8));
			if(tmpCodeName!="-1"){
				inputValue = tmpCodeName;
			}else{
			//	inputValue = $("#txtattstock").attr("mk") + $("#txtattstock").val();
			inputValue =  $("#txtattstock").val();
			}
			mytype="1";
			break;
		case "4":
			inputValue ="指标" + desc;
			mytype="4";
			break;
		case "2":
			inputValue = desc;
			mytype="2";
			break;
		case "3":
			var tmpCodeName = ExistCode(desc.substring(0,2),desc.substring(2,8));
			if(tmpCodeName!="-1"){
				inputValue = tmpCodeName + "画线";
			}else{
				inputValue = desc + "画线";
			}
			mytype="3";
			break;
	}
	
	type = parseInt(type);
	var op_param, inputHtml;
	if (type <= 100) {
		op_param = $(arr_attach[arr_attach.length-1]).attr("id") + "," + $($(arr_attach[arr_attach.length-1]).find("command")[0]).attr("op");
		inputHtml = '&nbsp;<input id="button'+ (arr_attach.length-1) +'" type="button" style="font-size:12px; font-family:\'宋体\'; cursor:pointer; height:19px; _margin-bottom:1px;border:1px solid #9fb3ca; background:url(img/ss_mail_icon6.gif) left top repeat-x;" mytype="'+ mytype +'" onclick="javascript:op('+ op_param +');oop('+ mytype +');ooop('+ $(arr_attach[arr_attach.length-1]).attr("id") +');return false;" value = "'+ inputValue +'"/>&nbsp;';
	} else {
		if (type == addvroom_type) {
			inputHtml = html_vroom.replace(/#ID#/g, (arr_attach.length-1));
			inputHtml = inputHtml.replace(/#TYPE#/g, addvroom_type);
		}
	};
	
	if (ifrmwrEditor == null)
	{
		//反向添加并且发邮件窗口并未打开
		g_content = inputHtml;
	}
	else
	{
		if(isButtonClick == true)
		{
			ifrmwrEditor.execCommand('inserthtml',inputHtml);	
		}
		else
		{
			ifrmwrEditor.execCommand('inserthtml',inputHtml);
		}
		isButtonClick = false;
	}
}
function load_users_change(users)
{
	for (var i=0; i < users.length; i++)
	{
		if(users[i].selectedStatus == 1)
		{
			$("#chk"+ users[i].id).attr("checked",true);
		}
		else
		{
			$("#chk"+ users[i].id).attr("checked",false);
		}
	
	}
}

var NeedLoadUsers = false;
var cacheuser = null;
var cacheindex = 0;
/*
function DelayLoadUsers()
{
	clearTimeout(mytimer);
	var shtml = [];
	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:74px;background:#fff;" title="'+ cacheuser[i].nm +'" >'+ cacheuser[cacheindex].nm +'</dd>');
			shtml.push('<dd class="ddtext" style="width:62px;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:74px;background:#E4F5FF;" title="'+ cacheuser[i].nm +'" >'+ cacheuser[cacheindex].nm +'</dd>');
			shtml.push('<dd class="ddtext" style="width:62px;background:#E4F5FF;padding-left:13px;" >'+ cacheuser[cacheindex].interactLvl +'</dd>');
		}
		cacheindex--;
		if (cacheindex <= -1) break;
	}
	var html = shtml.join("");
	$("#tbuserlist").append($(html));
	recordtime("第n次加载客户列表完成");
	if (cacheindex >-1) {
		mytimer = setTimeout("DelayLoadUsers()", 25);
	} else {
		// 选择用户操作
		G_load_users = true;
		$("#thuserschk").attr("style","");
		$("#mail_list_item_table_loading").hide();
		if (G_loaded == false)
		{
			recordend();
			G_loaded = true;
			
		}
	}
}
*/
function load_users(users)
{
	var shtml = [];
	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:74px;background:#fff;" title="'+ cacheuser[i].nm +'" >'+ cacheuser[i].nm +'</dd>');
			shtml.push('<dd class="ddtext" style="width:62px;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:74px;background:#E4F5FF;" title="'+ cacheuser[i].nm +'" >'+ cacheuser[i].nm +'</dd>');
			shtml.push('<dd class="ddtext" style="width:62px;background:#E4F5FF; padding-left:13px;" >'+ cacheuser[i].interactLvl +'</dd>');
		}
		cacheindex--;
	//	if (cacheindex <= cacheuser.length-31) break;
	}
	var html = shtml.join("");
	$("#tbuserlist").html(html);
	
	if (cacheindex > 0) {
		NeedLoadUsers = true;
	//	mytimer = setTimeout("DelayLoadUsers()", 25);
	}else{
		$("#thuserschk").attr("style","");
		G_load_users = true;
		G_loaded = true;
	//	$("#mail_list_item_table_loading").hide();
	}
}

//添加筛选条件
function load_filter()
{
	if(loadFilterState=="false")
	{  
		loadFilterState="true";
		var sdlstring = "<div style=\" height:100%; float:left;\">";
		for (var i=0; G_groups != null && i < G_groups.length; i++)
		{
			sdlstring += '<dd><label><input type="checkbox" onclick="javascript:stopBubble(event);" groupid="' + G_groups[i].id + '"/></label>' + G_groups[i].name + '</dd>';
		}
		sdlstring += '</div>';

		$("#dlGroup").html($("#dlGroup").html() + 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:stopBubble(event);" actionid="' + G_Actions[i].id + '"/></label>' + G_Actions[i].name + '</dd>';
		}
		sdlstring += '</div>';
		$("#dlAction").html($("#dlAction").html() + sdlstring);	
		//长期权限 type=1
		/*
		sdlstring = "";
		for (var key in G_Rights)
		{
			if (G_Rights[key].type=="1")
			{
				sdlstring += '<dd><label><input type="checkbox" onclick="javascript:stopBubble(event);" rightid="' + key + '"/></label>' + G_Rights[key].nm + '</dd>';
			}		
		}
		$("#dlRight").html($("#dlRight").html() + 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:auto; margin-right:66px; display:inline;"><label><input type="checkbox" onclick="javascript:stopBubble(event);" rightid="' + key + '"/></label>' + G_Rights[key].nm + '</dd>';
			}		
		}
		sdlstring += '</div>';	
		$("#dlTrialRight").html($("#dlTrialRight").html() + sdlstring);	
	}
}
//筛选确定
function GetUserFilterOK()
{
	var sFilter = "";
	//数组遍历开始记录开始
	//长期权限
/*	var dlRight=[];
	$("#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=[];
	$("#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=[];
	$("#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=[];
	$("#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];
				sFilter +="Right" + tmpkey.toString() + ";";
				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];
				sFilter +="Right" + tmpkey.toString() + ";";
				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];
					sFilter += "Action" + tmpkey.toString() + ";";
					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];
					sFilter += "Group" + tmpkey.toString() + ";";
					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;
	});
	if (sFilter != G_sFilter)
	{
		G_sFilter = sFilter;
		loadusershtml("");		
		GetUserFilter();
	}
	else
	{
		UserFilterImgStates();
		hideDiv('popSift');
	}
}


//判断当前筛选框是否显示勾选图片
function UserFilterImgStates()
{
	var imgststes=false;
	$("#popSift").find("input").each(function(){
		if(this.checked)
		{
			imgststes=true;			
			return false;
		}
	});	
	if(imgststes==true)
	{
		$("#btn_filter").hover(function(){
			$("#btn_filter").css("background-position","0px -40px");
		});
		$("#btn_filter").css("background-position","0px -40px");	
	}
	else
	{
		$("#btn_filter").hover(function(){
				$("#btn_filter").css("background-position","0px -20px");
		},function(){
			$("#btn_filter").css("background-position","0px 0px");
		});
		$("#btn_filter").css("background-position","0px 0px");
	}
}
//判断取消和X掉筛选对话框时取消页面勾选状态
function GetUserFilterCancel()
{
	var ischange = false;
	$("#dlRight dd").find("input").each(function(){
	if(this.checked)
		{
			$(this).attr("checked",false);		
			ischange = true;
		}
	});	
	$("#dlTrialRight dd").find("input").each(function(){
	if(this.checked)
		{
			$(this).attr("checked",false);		
			ischange = true;
		}
	});	
	$("#dlAction dd").find("input").each(function(){
		if(this.checked)
		{
			$(this).attr("checked",false);
			ischange = true;			
		}
	});	

	$("#dlGroup dd").find("input").each(function(){
		if(this.checked)
		{
				$(this).attr("checked",false);
				ischange = true;
		}
	});
	if (ischange && G_sFilter != "")
	{
		G_sFilter = "";
		$(G_users).each(function(index,value){value["filter"] = false;});
		loadusershtml("");
		GetUserFilter();
	}
}

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 load_brokerRight()
{
	if(loadBrokerRightState=="false")//判断是否加载长期权限和我的权限
	{		
		loadBrokerRightState="true";
		var sbrokerright = "";
		var slongright = "";
		var j = 0;
		for (var key in G_Rights)
		{
			if(typeof(G_broker.srv[key]) != "undefined")
			{
				if (G_Rights[key].type == "1")
				{
					sbrokerright += "<tr>";
					sbrokerright += "<td width='85'>" + ql_date_yyyymmdd(G_broker.srv[key].applyD) + "</td>";
					sbrokerright += "<td width='85'>" + ql_date_yyyymmdd(G_broker.srv[key].expireD) + "</td>";
					sbrokerright += "<td width='96'>" + G_Rights[key].nm + "</td>";
					sbrokerright += "<td width='86'>" + G_broker.srv[key].balance +  "</td>";
					sbrokerright += "<td width=''>" + G_broker.srv[key].balance + "</td>";
					sbrokerright += "</tr>";
					slongright += '<tr>';
					slongright += '<td width="54"><input type="checkbox" ctype="'+key+'" onclick="javascrpt:clongright(this);"/></td>';
					slongright += '<td width="153">' + G_Rights[key].nm + '</td>';
					slongright += '<td width="211"><input type="text" class="mail_system_long_input" id="long' + key + '"  onclick="WdatePicker({el:$dp.$(\'long' + key + '\'),maxDate:\''+ ql_date_yyyymmdd(G_broker.srv[key].expireD) +'\'})" style="display:none;"  readonly /><img id="img_long' + key + '" src="img/ss_mail_icon1.gif" onclick="WdatePicker({el:$dp.$(\'long' + key + '\'),maxDate:\''+ ql_date_yyyymmdd(G_broker.srv[key].expireD) +'\'})" style="display:none;"/></td>';
					slongright += '</tr>';
					j++;
				}
			}
		}
		if (j <= 6)
		{
			$("#tbbrokerright").css("width","466px");
			$("#tdscroll").hide();
		}
		$("#tblongright").html(slongright);
		$("#tbbrokerright").html(sbrokerright);
	}
}
//加载试用权限
function load_brokerTrialRight()
{
	if(loadBrokerTrialRightState=="false")//判断是否加载长期权限和我的权限
	{		
		loadBrokerTrialRightState="true";
		var sbrokerright = "";
		var slongright = "";
		var j = 0;	
		var selObj='<div class="link_record0" onMouseOver="hiLight(this)"  onmousedown="CheckMe(this,\'请选择\',\'请选择\');trialonchange(\'请选择\');"><ul><li>请选择</li></ul></div>';
		for (var key in G_Rights)
		{   
			if (G_Rights[key].type == "3")
			{
				selObj += '<div class="link_record0" onMouseOver="hiLight(this)" onmousedown="CheckMe(this,\''+ G_Rights[key].nm +'\',\''+ key.toString() +'\');trialonchange(\''+ key.toString() +'\');">';
				selObj +='<ul><li>'+ G_Rights[key].nm +'</li></ul></div>';
			}
		}
		$("#trialSelectmx").html(selObj);
	}
}
//试用权限下拉事件
function trialonchange(obj)
{	
	load_AllBrokerRight("2",true);
	var key =obj;
	if(key !="请选择")
	{
		if(G_broker.srv[key] != undefined)
		{
			var remaining = G_broker.srv[key].balance;
			$("#txttrialPoint").text("剩余数量:"+remaining.toString()+"个");
		}
		else
		{
			$("#txttrialPoint").text("剩余数量:0个");
		}
	}
	else
	{
		$("#txttrialPoint").text("");
	}
}
//加载短期权限列表
function load_brokerShortRight()
{
	if(loadBrokerShortRightState=="false")//判断是否加载长期权限和我的权限
	{		
		loadBrokerShortRightState="true";
		var sbrokerright = "";
		var slongright = "";
		var j = 0;		
		//var selObj=document.getElementById("GoldattstockSelect");
		var selObj='<div class="link_record0" onMouseOver="hiLight(this)"  onmousedown="CheckMe(this,\'请选择\',\'请选择\');trialonchange(\'请选择\');"><ul><li>请选择</li></ul></div>';
		for (var key in G_Rights)
		{   
			if (G_Rights[key].type == "2")
			{
//				var tmpOption=document.createElement("option");
//                selObj.options.add(tmpOption);
//                tmpOption.innerText=G_Rights[key].nm;
//                tmpOption.value=key.toString(); 
                
                selObj += '<div class="link_record0" onMouseOver="hiLight(this)" onmousedown="CheckMe(this,\''+ G_Rights[key].nm +'\',\''+ key.toString() +'\');trialonchange(\''+ key.toString() +'\');">';
				selObj +='<ul><li>'+ G_Rights[key].nm +'</li></ul></div>';
                
                $("#GoldattstockSelect").text(G_Rights[key].nm );//下拉放开后删除本行代码
                $("#GoldattstockSelect").attr("optionvlue",key.toString());//下拉放开后删除本行代码
                if(typeof(G_broker.srv[key])== "undefined"){
                	$("#txtRemainPoint").text("剩余：0次");//下拉放开后删除本行代码
                }else{
                	var tmpbalance=typeof(G_broker.srv[key].balance) != "undefined" ? G_broker.srv[key].balance : "0";
               		$("#txtRemainPoint").text("剩余：" + tmpbalance + "次");//下拉放开后删除本行代码
               	}
			}
		}
	//	$("#GoldattstockSelectmx").html(selObj);//下拉放开后放开本行代码
	}

}
//短期权限下拉事件
function shortrightchange(obj)
{
	load_AllBrokerRight("2",true);
	var key =obj;
	if(key !="请选择")
	{
		if(G_broker.srv[key] != undefined)
		{
			var remaining = G_broker.srv[key].balance;
			$("#txtRemainPoint").text("剩余:"+remaining.toString()+"次");
		}
		else
		{
			$("#txtRemainPoint").text("剩余:0次");
		}
	}
	else
	{
		$("#txtRemainPoint").text("");
	}
}

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;
					if(list_customers_state=="true"){
						change_users_html(this.id,false);
					}
				}
				else
				{
					if(list_customers_state=="true"){
						change_users_html(this.id,true);
					}
					this.selectedStatus = 1;
					
				}
			});
			$.each(G_groupslable,function(i,g_user){
				if (($.inArray("["+ g_user.nm +"]",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))
				{
					if(list_customers_state=="true"){
						change_users_html(this.id,false);
					}
					this.selectedStatus = 0;
				}
				else
				{
					if(list_customers_state=="true"){
						change_users_html(this.id,true);
					}
					this.selectedStatus = 1;
				}
			});
			$.each(G_groupslable,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_groupslable,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);
	}
	else
	{
		switch(ilisttab){
			case "list_customers":		
				load_users_change(G_users);		
				break;
			case "list_borkers":
				load_users_change(G_brokers);
				break;
			case "list_managers":		
				load_users_change(G_managers);
				break;	
			case "list_groups":
				load_users_change(G_groupslable);
				break;
			case "list_selected":
				load_list_selected("list_selected");
				break;
		}
	}
}

//勾选事件
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 txtsenderid = "#txtSender";
	var sendername = $(txtsenderid).val();
	if (sendername == "发送多人时请以英文分号分隔"){
		sendername = [""];
	}else{
		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 != "";});
		var tmpsendername=sendername.join(";")+";";
		if(tmpsendername==";"){
			tmpsendername="";
		}
		$(txtsenderid).val(tmpsendername);
	}
	else
	{
		$(txtsenderid).val(sname+";");
	}
	if ($(txtsenderid).val().length > 0)
	{
		$(txtsenderid).css("color","black");
	}
	getsumnum();
}
function sendNormal()
{
	var Action = "sender";
	var txtsenderid = "#txtSender";
	var tmpSenders = "";
	tmpSenders = $(txtsenderid).val();	
	if (tmpSenders == "" || tmpSenders =="发送多人时请以英文分号分隔")
	{
		alert("请选择收件人");
		return;
	}	
	var Senders = getsender("id");
	var SendersNames=getsender("nm");
	var aSenders = Senders.split(";");
	var userinfo = getSysUser();
	var scid = userinfo[0];
	
	if(aSenders!=null && aSenders.length>2000) {
		alert("本系统最大支持同时发送给2000人，您的收件人数超过上限，请重新选择！");
		return;
	}

	var sTitle = "";//邮件标题	
	var sMailbody = "";//邮件正文
	var procuids = "";
	var procuidates = "";
	var cids = "";
	//判断是否是普通邮件（0,1,2）
	switch (itab)
	{
		case "0":
			{	
				//此可部分代码 页面编辑删除附件操作
				var aprocuid = new Array();
				var videotext="";
				var seq = G_Parent.GLOBAL_Seq;
				var xml =ql_xml_stringtoxml("<xml>" + G_Parent.GLOBAL_Attach.replace(/\r/g, "") + "</xml>"); 
				var tmp_content = ifrmwrEditor.getContent();
				var tmp = document.createElement("DIV"); 
				tmp.innerHTML = tmp_content; 
				var buttons =  $(tmp).find("input:enabled");
				var arr_id = [];
				var arr_type = [];
				if(buttons != null && $(xml).find("attach").length > 0)
				{
					$.each(buttons,function(i,val){
						//arr_id[i] = {};
						arr_id[i] = $(val).attr("id");  //val.match(regEx_id)[0].replace("id=button","");
						//arr_id[i]["index"] = i;
						arr_type[i] = $(val).attr("mytype");  //val.match(regEx_type)[0].replace("mytype=","");
						
						if ($(val).attr("mytype")=="101")
						{
							videotext += "讲座标题：" + $(val).attr("title") +"</br>";
							videotext += "开始时间：" + $(val).attr("date") +" "+ $(val).attr("stime").substring(0, 2) +":"+ $(val).attr("stime").substring(2) +"</br>";
							videotext += "结束时间：" + $(val).attr("date") +" "+ $(val).attr("etime").substring(0, 2) +":"+ $(val).attr("etime").substring(2) +"</br>";
						}
					})

					var newbuttons = arr_id.sort(function (a,b) {
						if (a < b)
						{
							return -1
						}
						else
						{
							return 1;
						}
					});
					var imod = 0;
					$(newbuttons).each(function(index,value){
						var regop = new RegExp("javascript:op\\(" + value + ",","g"); 
						tmp_content = tmp_content.replace(regop,"javascript:op(" + index.toString() + ",");
					});
					ifrmwrEditor.setContent(tmp_content);//设置富文本为默认值
					$(xml).find("attach").each(function(index){
						var id = $(this).attr("id");
						var tmp_array = $.grep(arr_id,function(val){return val != id});
						if (tmp_array.length == 0)
						{
							DeleteAttach(seq,parseInt(id));
							imod++;
						}
						else
						{
							aprocuid.push($(this).attr("type"));
						}
					});
				}
			}
			
			//拼写视频固定模板信息	
			if(videotext !="")	
			{	
				var tmphtml="<div style=\"border-style:solid;border-width:1px;margin-top:25px;line-height:14px; padding:8px;\">友情提示:";
				tmphtml+= videotext+"</div>";	
				sMailbody = ifrmwrEditor.getContent()+"\r\n"+tmphtml;
			}else{
				sMailbody = ifrmwrEditor.getContent();
			}
			
			for (var i = 0; i < aprocuid.length; i++)
			{
				procuids = procuids + aprocuid[i] + ",";
			}
			if (procuids.length > 0)
			{
				procuids = procuids.substring(0,procuids.length-1);
			}
			/*
			sTitle = $("#txtTitle").val();
			
			{	
				//此可部分代码 页面编辑删除附件操作
				var aprocuid = ["","","",""];
				var seq = G_Parent.GLOBAL_Seq;
				alert(G_Parent.GLOBAL_Attach);
				a = bbbccc;
				var xml =ql_xml_stringtoxml("<xml>" + G_Parent.GLOBAL_Attach.replace(/\r/g, "") + "</xml>"); 
				var tmp_content = ifrmwrEditor.getContent();
				/  *
				var regEx = /<input\s*([^>]*)>/gim;
				var regEx_id = /id=([^\s|>]*)/g;
				var regEx_type = /mytype=([^\s|>]*)/g;
				//var regEx_src = /<a([^>]*) src=\s*([^\s|>]*)([^>]*)/gi
				//cont = cont.replace(regEx_src, "$2"); 处理图片地址
				var buttons = tmp_content.match(regEx);
				*   /
				var tmp = document.createElement("DIV"); 
				tmp.innerHTML = tmp_content; 
				var buttons =  $(tmp).find("input:enabled");
				var arr_id = [];
				var arr_type = [];
				if(buttons != null && $(xml).find("attach").length > 0)
				{
					$.each(buttons,function(i,val){
						//arr_id[i] = {};
						arr_id[i] = $(val).attr("id").replace("button","");  //val.match(regEx_id)[0].replace("id=button","");
						//arr_id[i]["index"] = i;
						arr_type[i] = $(val).attr("mytype");  //val.match(regEx_type)[0].replace("mytype=","");
					})

					var newbuttons = arr_id.sort(function (a,b) {
						if (a < b)
						{
							return -1
						}
						else
						{
							return 1;
						}
					});
					var imod = 0;
					$(newbuttons).each(function(index,value){
						var regop = new RegExp("javascript:op\\(" + value + ",","g"); 
						tmp_content = tmp_content.replace(regop,"javascript:op(" + index.toString() + ",");
					});
					ifrmwrEditor.setContent(tmp_content);//设置富文本为默认值
					$(xml).find("attach").each(function(index){
						var id = $(this).attr("id");
						var tmp_array = $.grep(arr_id,function(val){return val == id});
						if (tmp_array.length == 0)
						{
							DeleteAttach(seq,parseInt(id));
							imod++;
						}
						else
						{
							switch ($(this).attr("type"))
							{
								case "1":
									aprocuid[0]="1";
								break;
								case "2":
									aprocuid[1]="2";
								break;
								case "3":
									aprocuid[2]="3";
								break;
								case "4":
									aprocuid[3]="4";
								break;
							}
						}
					});
				}
			}
			sMailbody = ifrmwrEditor.getContent();
			for (var i=0; i<4 ; i++)
			{
				if (aprocuid[i] != "")
				{
					procuids = procuids + aprocuid[i] + ",";
				}
			}
			if (procuids.length > 0)
			{
				procuids = procuids.substring(0,procuids.length-1);
			}
			*/
		break;
		case "1":
		//	sTitle = $("#txtTitle").val();
			sMailbody = ifrmwrEditor.getContent();
			if ($("#txtGoldCode").val() == "" || $("#txtGoldCode").val() == "请输入股票代码")
			{
				alert("请输入股票代码");
				return;
			}
			var tmpCodeName=ExistCode($("#txtGoldCode").val().substring(0,2),$("#txtGoldCode").val().substring(2,8));		
			if (tmpCodeName == "-1")
			{
				alert("您输入的股票代码有误，请查看市场是否选择正确！");
				return;
			}
			var text=$("#GoldattstockSelect").text();
			if(text == "请选择")	
			{
				alert("请选择产品");
				return;
			}
			procuids=$("#GoldattstockSelect").attr("optionvlue");
			var tmphtml="<div style=\"border-style:solid;border-width:1px;margin-top:25px;line-height:14px; padding:8px;\">您好！</br>&nbsp;&nbsp;&nbsp;&nbsp;您的服务人员为您发送了"+tmpCodeName+"(" +  $("#txtGoldCode").val() + ")的钱龙黄金眼功能，请使用您的电脑金融终端查看该股票的黄金眼主力数据！</br></div>";
			proc_mkcode_str = tmpCodeName +"(" + $("#txtGoldCode").val() + ")";
			sMailbody=sMailbody+tmphtml;
		break;
		case "2":
		//	sTitle = $("#txtTitle").val();
			//拼写固定模板信息
			
			var tmphtml="<div style=\"border-style:solid;border-width:1px;margin-top:25px;line-height:14px; padding:8px;\">您好！您的服务人员为您开通以下权限:</br>";
			var tmpErr="";
			var tmpChkStuts = false;
			$("#tblongright tr").each(function()
			{
				
				var chk = $(this).children("td:eq(0)").find("input");
				if(chk.get(0).checked == true)
				{
					tmpChkStuts=true;
					var text = $(this).children("td:eq(1)").text();
					var date = $(this).children("td:eq(2)").find("input").val();
					procuids += chk.attr("ctype") + ",";
					procuidates += date.replace(/-/g,"") + ",";
					if(date=="")
					{	
						tmpErr+=text+"、";
						return;	
					}
					tmphtml+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+text+"，到期日期为:"+date+"；</br>";			
				}
			})
			var inputHtml = '&nbsp;<input id="btn22" type="button" class="mail_system_template" style= "color:#ff0000" onclick="javascript:loginagain();return false;" value = "重新登录享受收费功能"/>&nbsp;';
			tmphtml+="友情提示："+inputHtml+"</div>";
			if (tmpChkStuts==false)
			{	
				alert("请选择需要开通的长期权限！");
				return;
			
			}
			tmpErr=tmpErr.substring(0,tmpErr.length-1);
			if(tmpErr!="")
			{
				alert("请设置:"+tmpErr+"  的到期时间");
				return;
			}
			sMailbody = ifrmwrEditor.getContent()+"\r\n"+tmphtml;
		break;
		case "3":			
		//	sTitle = $("#txtTitle").val();
			var txttrialPoint = $("#txttrialPoint").text();			
			//拼写固定模板信息			
			var tmphtml="<div style=\"border-style:solid;border-width:1px;margin-top:25px;line-height:14px; padding:8px;\">您好！</br>&nbsp;&nbsp;&nbsp;&nbsp;您的服务人员为您开通以下试用产品:";
			var tmpErr="";		
			var text=$("#trialSelect").text();  
			if(text == "请选择")	
			{
				alert("请选择试用产品");
				return;
			}
			procuids=$("#trialSelect").attr("optionvlue");
			tmphtml+="&nbsp;"+text+"</br></br>";
			var inputHtml = '&nbsp;<input id="btn22" type="button" class="mail_system_template" style= "color:#ff0000" onclick="javascript:loginagain();return false;" value = "重新登录享受收费功能"/>&nbsp;';
			tmphtml+="友情提示："+inputHtml+"</div>";			
			if(txttrialPoint==0)
			{
				alert("点数不足");
				return;
			}		
			sMailbody = ifrmwrEditor.getContent()+"\r\n"+tmphtml;
		break;
	}
	sTitle = $("#txtTitle").val().replace(/(^\s*)|(\s*$)/g, "");
	if (sTitle == "")
	{
		alert("标题不能为空，请填写！");
		return;
	}
	if (sTitle.length >200)
	{
		alert("标题内容过多，请填写少于200个字符！");
		return;
	}

	sMailbody=	checkimgstrip(sMailbody);//过滤邮件中img标签

	if (G_TOTALIMGSIZE() < total_imgsize)
	{
		alert("正文中插入的图片过多!图片总大小不得大于5M");
		return;
	}

	if (procuids.substring(procuids.length - 1) == ",")
	{
		procuids = procuids.substring(0,procuids.length - 1);
	}
	if (procuidates.substring(procuidates.length - 1) == ",")
	{
		procuidates = procuidates.substring(0,procuidates.length - 1);
	}
	if (Senders.substring(Senders.length - 1) == ";")
	{
		Senders = Senders.substring(0,Senders.length - 1);
	}
	cids = Senders.replace(/;/g,",");
	CreateMailXML(Action,Senders.toLowerCase(),sTitle,sMailbody,cids,procuids,procuidates,SendersNames);
}

function CreateMailXML(Action,Senders,sTitle,sMailbody,cids,procuids,procuidates,SendersNames)
{
	//	var today = new Date();
	//	new_isd = today.getMinutes() * 60 * 1000 + today.getSeconds() * 1000 + today.getMilliseconds();
	//	difftime = new_isd - isd;
	//	isd = new_isd;
	//	document.getElementById("showtime").innerHTML = document.getElementById("showtime").innerHTML + difftime.toString() + "    ";
	//	document.getElementById("showtime").innerHTML = document.getElementById("showtime").innerHTML + today.getYear() + "-" + today.getMonth() + "-" + today.getDay() + ":" + today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds() + ":" + today.getMilliseconds() + "(start save and send)</br>";
	    $.ajax({
        url:"mailtemplate.xml",
        dataType:"text",
        success:function(text){
			var ltext = "";
			ltext = text.replace(" attrib=\"\"","");
			var xml = ql_xml_stringtoxml(ltext.replace(/\r/g, ""));
			var nd_mail = $($(xml).find("mail")[0]);
			var nd_type = $($(xml).find("type")[0]);
			var nd_from = $($(xml).find("from")[0]);
			var nd_to = $($(xml).find("to")[0]);
			var extra = "";
			nd_mail.attr("seq",NewEmailSeq);
			nd_mail.attr("timestamp",ql_date_yyyymmddhhss(new Date()));
			/*经纪人没有回复这个类型，回复就是普通邮件
			if(sourceSeq != "" && sourceSeq != undefined)
			{
				if(itab == "0")
				{
					$($(xml).find("type")[0]).text(sourceSeq+","+sourceType);
					$($(xml).find("type")[0]).attr("no","2");
				}				
			}
			else
			*/
			{

				if (procuids != "")
				{
					nd_type.attr("subno",procuids);
				}
				switch(itab)
				{
					case "0":
						extra = "type=0";
						nd_type.attr("no","0");
						$($(xml).find("to")[0]).attr("name",SendersNames);
						getAttach(NewEmailSeq);
						break;
					case "1":
						//if ($("#txtGoldattstock").attr("code") == "1001")
						{
						extra = "type=4";
							nd_type.attr("no","4");
							$($(xml).find("goldcode")[0]).text($("#txtGoldCode").attr("mk") + "," + $("#txtGoldCode").val().substring(2,8) + "|" + $("#GoldattstockSelect").attr("optionvlue") + "|" + $("#GoldattstockSelect").text());
						}
						nd_to.attr("name",SendersNames);
						break;
					case "2":
						extra = "type=3";
						nd_type.attr("no","3");
							var tmpType="";						//长期权限
							$("#tblongright tr").each(function()
							{
								var chk = $(this).children("td:eq(0)").find("input");
								if(chk.get(0).checked == true)
								{								
									var typeID=$(chk).attr("ctype");														
									tmpType+=typeID+",";			
								}
							})
							tmpType=tmpType.substring(0,tmpType.length-1)
						nd_type.text(tmpType);				
						nd_to.attr("name",SendersNames);
						break;
					case "3":
						extra = "type=6";
						nd_type.attr("no","6");
						nd_to.attr("name",SendersNames);
						break;
				}
			}			
			nd_from.text(getAccountid());
			nd_from.attr("name",G_broker["info"].nm);
			if (Senders == "")
			{
				alert('请输入收件人！');
				return;
			}
			else
			{
				nd_to.text(Senders);
			}
			//$($(xml).find("extra")[0]).text(extra == "" ? "title=" + UrlEncode(sTitle) : extra + "&title=" + UrlEncode(sTitle));
			$($(xml).find("title")[0]).text(encodeString(sTitle));
			$($(xml).find("content")[0]).text("<![CDATA[" + sendattachfiles(sMailbody) + "]]>");
			if ( G_TOTALFILESIZE() < total_filesize)
			{
				alert("附件过多!附件总大小不得大于10M");
				return;
			}
			var smail = ql_xml_xmltostring(xml).replace("</mail>",G_Parent.GLOBAL_Attach + "</mail>");
			//提交用户长期权限修改
			if (itab == "2")
			{
				var rtn = SetProcus(cids,procuids,procuidates).replace(/\r\n/g,"");
				switch (rtn)
				{
					case "1":
						break;
					case "-1":
						alert("分配权限失败,缺少参数！");
						return;
						break;
					case "-2":
						alert("分配权限失败,无效参数！");
						return;
						break;
					case "-3":
						alert("分配权限失败,经纪人权限不足！");
						return;
						break;
					case "-5":
						alert("您只能给你的客户分配权限！");
						return;
						break;
					case "-11":
						alert("权限类邮件仅限于发送给股民，您的收件人中包含了服务人员，请重新输入！");
						return;
						break;
					default:
						alert("分配权限失败！");
						return;
				}
			}
			//提交用户试用权限修改
			if (itab == "3")
			{
				var rtn = SetTrialRight(cids,procuids).replace(/\r\n/g,"");
				switch (rtn)				
				{
					case "1":
						break;
					case "-1":
						alert("缺少参数！");
						return;
						break;
					case "-2":
						alert("无效参数！");
						return;
						break;
					case "-3":
						alert("服务包过期！");
						return;
						break;
					case "-4":
						alert("服务包重叠！");
						return;
						break;
					case "-5":
						alert("用户不存在！");
						return;
						break;
					case "-6":
						alert("缺少点数！");
						return;
						break;
					case "-8":
						alert("操作失败！");
						return;
						break;
					case "-9":
						alert("系统错误！");
						return;
						break;
					case "-11":
						alert("权限类邮件仅限于发送给股民，您的收件人中包含了服务人员，请重新输入！");
						return;
						break;
					default:
						alert("分配权限失败！");
						return;
						break;
				}
			}
			
			if (itab == "1")
			{
				var rtn = checkRightShort(cids,procuids).replace(/\r\n/g,"");
				switch (rtn)
				{
				case "1":
				break;
				case "-1":
					alert("缺少参数！");
					return;
					break;
				case "-2":
					alert("无效参数！");
					return;
					break;
				case "-3":
					alert("服务包过期！");
					return;
				break;
				case "-4":
					alert("服务包重叠！");
					return;
					break;
				case "-5":
					alert("用户不存在！");
					return;
					break;
				case "-6":
					alert("缺少点数！");
					return;
					break;
				case "-8":
					alert("操作失败！");
					return;
					break;
				case "-9":
					alert("系统错误！");
					return;
					break;
				case "-11":
					alert("权限类邮件仅限于发送给股民，您的收件人中包含了服务人员，请重新输入！");
					return;
					break;
				default:
					alert("分配权限失败！");
					return;
				break;
				}
			}
			smail = smail.replace("</extra>",(extra == "" ? "title=" + encodeURIComponent(sTitle) : extra + "&title=" + encodeURIComponent(sTitle)) + "</extra>");
			var mySeq = SaveMail(smail);/*返回格式（邮件编号|邮件大小）*/
			var mySeqs = mySeq.split("|");
			if (mySeqs.length > 1)
			{
				if (Number(mySeqs[1]) > 65535)
				{
					alert("邮件总大小超出系统限制,建议尽量通过附件方式发送大型文档！");
					return;
				}
			}
			mySeq = mySeqs[0];
			if (mySeq == "-1")
			{
				popupDiv("dvWait");
				sendMailMessage("-4");//发送失败
				return;
			}
			if (mySeq == "0"  || mySeq == "")
			{
				alert("意外失败！");
				return;
			}
			SetAttrib(mySeq + "\r\n65536");
			if (NewEmailSeq == mySeq)
			{
				var tmpSenders = Senders.split(";");
				g_senders = tmpSenders;
				if(sourceSeq != "" && sourceSeq != undefined && itab == "0")
				{
					g_sendlogtype = "A3";
					g_sendlogtxt = ","+sourceSeq+","+sourceType+","+sourceFrom;
				}
				else
				{
					g_sendlogtype = "A4";
					g_sendlogtxt = ","+sourceSeq+","+sourceType+","+sourceFrom;
				}
				if (NewEmailSeq == SendMail(NewEmailSeq))
				{

					//NewEmailSeq = NewMail();
					//G_Parent.GLOBAL_Seq = NewEmailSeq;
					sendprocess = setTimeout("sendfail()",15000);
					popupDiv("dvWait");
				}
				else
				{
					popupDiv("dvWait");
					sendMailMessage("-3");//发送失败
				}					
			}
			else
			{
				popupDiv("dvWait");
				sendMailMessage("-3");//发送失败
			}
		}
    })
}

function clongright(obj)
{
	if(obj.checked)
	{
		$(obj).parent().parent().find("td:eq(2) input").each(function(){
				$(this).attr("style","");
		})
		$(obj).parent().parent().find("img").each(function(){
				$(this).attr("style","");
		})
	}
	else
	{
		$(obj).parent().parent().find("td:eq(2) input").each(function(){
			$(this).attr("style","display:none;");
			$(this).attr("value","");
		})
		$(obj).parent().parent().find("img").each(function(){
			$(this).attr("style","display:none;");
		})
	}
}

function myload(){
	recordtime("必要的JS文件加载完成");
	$("#txtSender").val("发送多人时请以英文分号分隔");
	initattachsetting();
	var p = new Poly9.URLParser(window.location.href);	
	var stype = p.getParameter("type");	
	var sOldSeq = "";
	
	var stime = 0;
	if  (p.getParameter("t") != null)
		stime = g_isd_start - parseInt(p.getParameter("t"),10);
	recordstart(stime);

	var stab = p.getParameter("tab");	

	recordtime("获取URL参数完成");
	initUsersData();

	recordtime("获取平台数据完成(远程/本地缓存)完成");
	G_filter = G_users;
	G_filter_managers =G_managers;
	G_filter_brokers =G_brokers;
	G_filter_groupslable=G_groupslable;	
	changelist('list_groups');//分组标签默认显示
	if (stab == null)
	{
		stab = "0";
	}
	changeTab(stab,"btn");
	if (stype ==2.5)//转发
	{
		var sOldSeq = p.getParameter("seq");
		NewEmailSeq = transpondReadMail(sOldSeq);
		G_Parent.GLOBAL_Seq = NewEmailSeq;
		reloadattachs();
		if (attachfiles.length >0)
		{
			$("#contentarea").attr("style","height:250px; margin-top:20px;");
			ifrmwrEditor.setHeight(200);
			ifrmwrEditor.body.style.height = "200px";
		}
		else
		{
			$("#contentarea").attr("style","height:270px;");
			ifrmwrEditor.setHeight(220);
			ifrmwrEditor.body.style.height = "220px";
		}
		getAttach(NewEmailSeq);
		$("#tab_button_1").removeAttr("onclick");
		$("#tab_button_3").removeAttr("onclick");
		$("#tab_button_1").attr("class","mail_system_11");
		$("#tab_button_3").attr("class","mail_system_33");
		ifrmwrEditor.setContent(g_content);	
	}
	else if (stype == 2) //回复
	{
		var sOldSeq = p.getParameter("seq");
		ReadMail(sOldSeq);
		NewEmailSeq = NewMail();
		G_Parent.GLOBAL_Seq = NewEmailSeq;
		ifrmwrEditor.setContent(g_content);	
	}
	else 
	{
		if (p.getParameter("seq") != null) //反向添加附件
		{
			G_Parent.GLOBAL_Seq = p.getParameter("seq");
			NewEmailSeq = G_Parent.GLOBAL_Seq;
			stype = 0;
			getAttach(NewEmailSeq);
			AddAttach();
		}
		else 
		{
			if (p.getParameter("usernamekey") != null) //从平台过来的调用，写邮件给某些人
			{
				stype = 0;
				NewEmailSeq = NewMail();
				G_Parent.GLOBAL_Seq = NewEmailSeq;
				var key = p.getParameter("usernamekey");
				var odata = client_data_load(key,"0");
				if (odata != null)
				{
					if(odata.dValue !="")
					{
						$("#txtSender").val(odata.dValue+";");
					}
				}
				senderMK = p.getParameter("mk"); //盯盘过来的市场代码
				senderCODE = p.getParameter("code"); //盯盘过来的商品代码
				if(senderMK != undefined &&senderCODE != undefined && senderMK!="" && senderCODE!="")
				{	
					senderMK=senderMK.toUpperCase();
					$("#txtGoldCode").val(senderMK+senderCODE);
					$("#txtGoldCode").attr("mk",senderMK);
					var tmpCodeName=ExistCode(senderMK,senderCODE);		
					if (tmpCodeName != "-1")
					{
						$("#txtTitle").val("黄金眼主力数据赋权 代码：" + senderCODE + tmpCodeName);
					}
				}
			}
			else //新建邮件
			{
				stype = -1;
				NewEmailSeq = NewMail();
				G_Parent.GLOBAL_Seq = NewEmailSeq;
			}
		}
	}
	recordtime("解析本次页面需要执行的动作完成");
	$("#startshow").hide();
	//shortrightlist();
	log.info("wrEditor write completed");
	recordtime("加载可编辑输入框完成(onload事件并未包含)");
	SynchroniseSender($("#txtSender").val(),false);
	recordtime("显示列表第一次完成");
	$(".mail_list_top").find("span:last").hover(function(){
		$(this).css("text-decoration","underline");
	},function(){
		$(this).css("text-decoration","none");
	});	

	$(".code_list li").find("span").hover(function(){
		$(this).css("background","#aadaff");
	},function(){
		$(this).css("background","none");
	});	
	$(".code_list").find("li:last").css("border","none");

	if ($("#txtSender").val() == "发送多人时请以英文分号分隔")
	{
		$("#txtSender").css("color","gray");
	}
	else
	{
		$("#txtSender").css("color","black");
	}
//筛邮件样式
	$("#btn_filter").hover(function(){
		$("#btn_filter").css("background-position","0px -20px");
	},function(){
		$("#btn_filter").css("background-position","0px 0px");
	});
	
	recordtime("页面onload事件完成");
	recordtime("---------------------华丽的分割线--------------------------");
	$(".attachment dd").hover(function(){
		$(this).css("background","#e4f5ff");
	},function(){
		$(this).css("background","none");
	});

	$("#attachlist li").live("mouseover",function(){
		$(this).css("background","#e4f5ff");
	});
	$("#attachlist li").live("mouseout",function(){
		$(this).css("background","none");
	}); 
	getsumnum();
	
	//普通邮件
	tas=new mSift('tas',10);
	//指定文本框对象建立 
	tas.Create("txtattstock");
	//黄金眼
	//建立实例，第一个参数是实例对象的名称，第二个是最多显示的数量 
	tgc=new mSift('tgc',10); ;
	//指定文本框对象建立 
	tgc.Create("txtGoldCode");
	ts=new iSift('ts',10); ;
	//指定文本框对象建立 
	ts.Create("txtSender");
	
	//设置客户端邮件复制模拟ctr+v
	initpastesetting(1);
	$("#txtTitle").focus();
	var sSign = getSign();
	if (sSign != "")
	{
		default_content = "<p><br /><br /></p>---------------------------------------------------<br /><div type=\"sign\">" + getSign() + "<div><!--end_sign-->";
	}
	ifrmwrEditor.setContent(ifrmwrEditor.getContent() + default_content);
}


//关闭推荐选股对话框
function divattstockclose()
{
	isButtonClick = false;
	if(tas !=null)
	{
		tas.Clear();
	}
	$('#divattstock').hide();

}

function myunload()
{
	pinyin = null; //当前用户列表所选的首字母标签
	itab = null;
	NewEmailSeq = null;
	sourceSeq = null;
	sourceType = null;
	sourceFrom=null;
	sendMK = null; //当前市场
	sendCODE = null; //当前商品
	sendprocess = null;
	sendMailTimeState=null;//发送邮件计时是否启用
	loadBrokerRightState=null;//长期权限、我的权限是否已加载完成
	loadBrokerTrialRightState=null;//试用权限是否加载完成
	loadBrokerShortRightState=null;//短期权限是否加载完成
	loadFilterState=null;//筛选是否已加载完成
	G_sFilter = null;
	replaceHtml = null;
	default_content=null;
	isButtonClick = false;
	g_content = null; //文本内容
	g_sendlogtype = null;
	g_sendlogtxt = null;
	g_senders = null;
	g_gid = null;

	mytimer = null;

	list_customers_state=null;
	list_groups_state=null;
	list_borkers_state=null;
	list_managers_state=null;
	list_selected_state=null;
	G_filter_managers=null;
	G_filter_brokers=null;
	G_filter_groupslable=null; 
	G_filter_selecteds=null;
	G_selecteds=null;
	ilisttab=null;
	G_descs =null;	
	chkall_managers_states=null;
	chkall_brokers_states=null;
	chkall_users_states=null;
	G_chkalls=null;
	
	G_users_hash=null;
	G_brokers_hash=null;
	G_managers_hash=null;
	G_users_hash_name=null;
	G_brokers_hash_name=null;
	G_managers_hash_name=null;
	ifrmwrEditor = null; //富文本编辑框的引用
	
	
	tas = null;
	tgc = null;
	ts = null;

}




/*
*用户列表标签切换
*/
function changelist(evid)
{
	$("#mail_list_item_table_loading").show();
	if ($("#"+evid).hasClass("mail_list_sel"))
	{
		$("#mail_list_item_table_loading").hide();
		return;
	}
	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")
	}
	$("#dl_list_groups").html("");	
	$("#dl_list_borkers").html("");	
	$("#dl_list_managers").html("");	
//	$("#tbuserlist").html("");	
	$("#dl_list_selected").html("");	
	
	
	$("#table_grouplist").hide();
	$("#table_borkerlist").hide();
	$("#table_managerlist").hide();
	$("#table_userlist").hide();
	$("#table_selectedlist").hide();
	
	
	ilisttab = evid;//记录当前标签id
	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";
			$("#mail_list_item_table_loading").hide();
			break;
		case "list_borkers":
			G_col=1;
			$("#thbrokerschk").attr("style","display:none");
			G_filter_brokers =G_brokers;
			$("#mail_list_item_table").attr("class","mail_list_item item_less");
			$("#btn_filter").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);
			}
			$("#mail_list_item_table_loading").hide();
			break;
		case "list_managers":
			G_col=3;
			$("#thmanagerschk").attr("style","display:none");
			G_filter_managers =G_managers;
			$("#mail_list_item_table").attr("class","mail_list_item item_less");
			$("#btn_filter").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);
			}			
			$("#mail_list_item_table_loading").hide();
			break;
		case "list_customers":
			G_col=5;
			$("#thuserschk").attr("style","display:none");
			G_filter = G_users;
			$("#mail_list_item_table").attr("class","mail_list_item item_less");
			$("#btn_filter").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);
			}
			G_user_do_states=$("#span_do_5").text();
			$("#mail_list_item_table_loading").hide();
			break;
		case "list_selected":
			G_col=8;
			$("#thselectechk").attr("style","display:none");
			$("#mail_list_item_table").attr("class","mail_list_item item_less");
			$("#btn_filter").hide();
			$("#list_navigation").show();
			$("#table_selectedlist").show();
			LoadUserFirstTime(evid);//加载已选	
			list_selected_state="true";//加载客户列表状态—选中
			$("#thselectechk").attr("style","");
			$("#thselectechk").attr("checked",true);
			$("#mail_list_item_table_loading").hide();
			
			break;
	}
}

/*
*经纪人加载用户列表
*/
function LoadUserFirstTime(evid)
{	
	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($("#"+G_user_pinyin_states),'ALL');
				changePinYin_states($("#"+G_user_pinyin_states));
				GetUserFilter();
			}
			break;
		case "list_selected":
			if(list_selected_state=="false"){
				changePinYin_states($("#pinyin_all"));
				load_list_selected(evid);	
			}else{
				changePinYin($("#pinyin_all"),'ALL');
			}
			break;
	}
}
/*
*加载分组列表
*/
function load_list_groups(users,evid){
	var shtml = [];		
	for (var i=0; users != null && i < users.length; i++)
	{
		if(i%2==0){
			shtml.push('<dd style="width:25px; background:#fff;">');
			if(users[i].selectedStatus == 1){
				shtml.push('<input id="chk'+users[i].id +'" type="checkbox" onclick="javascript:chgSender_list(this,\''+ evid +'\'); stopBubble(event);" userid="' + users[i].id + '" username="'+ users[i].nm +'" checked="checked"/></dd>');
				shtml.push('<dd class="ddtext" style="width:212px; background:#fff;">' + users[i].nm +'('+ users[i].num + '人)</dd>');
			}else{
				shtml.push('<input id="chk'+users[i].id +'" type="checkbox" onclick="javascript:chgSender_list(this,\''+ evid +'\'); stopBubble(event);" userid="' + users[i].id + '" username="'+ users[i].nm +'" /></dd>');
				shtml.push('<dd class="ddtext" style="width:212px; background:#fff;">' + users[i].nm +'('+ users[i].num + '人)</dd>');
			}
		}else{
			shtml.push('<dd style="width:25px; background:#E4F5FF;">');
			if(users[i].selectedStatus == 1){
				shtml.push('<input id="chk'+users[i].id +'" type="checkbox" onclick="javascript:chgSender_list(this,\''+ evid +'\'); stopBubble(event);" userid="' + users[i].id + '" username="'+ users[i].nm +'" checked="checked"/></dd>');
				shtml.push('<dd class="ddtext" style="width:212px; background:#E4F5FF;">' + users[i].nm +'('+ users[i].num + '人)</dd>');
			}else{
				shtml.push('<input id="chk'+users[i].id +'" type="checkbox" onclick="javascript:chgSender_list(this,\''+ evid +'\'); stopBubble(event);" userid="' + users[i].id + '" username="'+ users[i].nm +'"/></dd>');
				shtml.push('<dd class="ddtext" style="width:212px; background:#E4F5FF;">' + users[i].nm +'('+ users[i].num + '人)</dd>');
			}
		}
	}
	var html = shtml.join("");
	$("#dl_"+ evid).html(html);
}

/*
*加载已选列表
*/
function load_list_selected(evid)
{
	//从分组数组中过滤出已选对象
	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=G_filter_groupslable.concat(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].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:74px;background:#fff;"title="'+ cacheuser[i].nm +'">'+ cacheuser[i].nm +'</dd>');
			shtml.push('<dd class="ddtext" style="width:62px;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:74px;background:#E4F5FF;" title="'+ cacheuser[i].nm +'">'+ cacheuser[i].nm +'</dd>');
			shtml.push('<dd class="ddtext" style="width:62px;background:#E4F5FF;" style="padding-left:13px;">'+ cacheuser[i].interactLvl +'</dd>');
		}
	}
	var html = shtml.join("");
	$("#dl_"+ evid).html(html);
//	$("#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:74px;background:#fff;" title="'+ cacheuser[i].nm +'">'+ cacheuser[i].nm +'</dd>');
			shtml.push('<dd class="ddtext" style="width:62px;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:74px;background:#E4F5FF;" title="'+ cacheuser[i].nm +'">'+ cacheuser[i].nm +'</dd>');
			shtml.push('<dd class="ddtext" style="width:62px;background:#E4F5FF;" style="padding-left:13px;">'+ cacheuser[i].interactLvl +'</dd>');
		}	
	}
	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:149px;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:149px;background:#E4F5FF;" >'+ cacheuser[i].nm +'</dd>');
		}
	}
	var html = shtml.join("");
	$("#dl_"+ evid).html(html);

}

/*
*勾选事件
*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 txtsenderid = "#txtSender";
	var	 sendername = $(txtsenderid).val();
	if (sendername == "发送多人时请以英文分号分隔")
	{
		sendername = [""];
	}
	else
	{
		sendername = $.trim(sendername).split(";");
	}
	var sname="";
	if(evid=="list_groups"){
		sname = "["+$(value).attr("username")+"]";
	}else{
		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 != "";});
		var tmpsendername=sendername.join(";")+";";
		if(tmpsendername==";"){
			tmpsendername="";
		}
		$(txtsenderid).val(tmpsendername);
	}
	else
	{
		$(txtsenderid).val(sname+";");
	}
	if ($(txtsenderid).val().length > 0)
	{
		$(txtsenderid).css("color","black");
	}
	getsumnum();
}
/*
*根据标签判断是否重新加载用户列表数据
*/
function loadusershtml(pinyin_states)
{
	if (ilisttab=="list_customers"){
		if(pinyin_states!=""){
			G_user_pinyin_states=pinyin_states;	
		}
		G_filter = $.grep(G_users,function(v){
		return filterPinyin(pinyin,v);
		});
		load_users(G_filter);
	}
}
/*
*按照首字母筛选用户列表根据分组标签
*/
function GetUserFilter()
{
	switch (ilisttab){
		case "list_customers":	
			$("#span_do_5").text(G_user_do_states);	
			$("#thuserschk").attr("style","");
			$("#mail_list_item_table_loading").hide();
			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;});	
			change_users_html(user[0].id,value.checked);
			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();
	if (sendername == "发送多人时请以英文分号分隔")
	{
		sendername = [""];
	}
	else
	{
		sendername = $.trim(sendername).split(";");
	}
//	var sname = $(value).attr("username");
	var sname="";
	if(usertype=="group"){
		sname = "["+$(value).attr("username")+"]";
	}else{
		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 != "";});
		var tmpsendername=sendername.join(";")+";";
		if(tmpsendername==";"){
			tmpsendername="";
		}
		$(txtsenderid).val(tmpsendername);		
	}
	else
	{
		$(txtsenderid).val(sname+";");
	}
	if ($(txtsenderid).val().length > 0)
	{
		$(txtsenderid).css("color","black");
	}
	getsumnum();
}
/*
*用户列表勾选（全选）
*/
function allsender(obj,evid)
{	
	var users = [];
	var user=[];
	var txtsenderid = "#txtSender";
	var	sendername=";";
	var usertype="";
	var sname="";
	sendername = ";"+$.trim($(txtsenderid).val());
	if (sendername == ";发送多人时请以英文分号分隔")
	{
		sendername = ";";
	}
	if(obj.checked)
	{
		$("#"+evid).find("input").each(function(index,value){
			value.checked = true;					
			usertype=$(value).attr("usertype");	
			if(usertype=="group"){
				sname = "["+value.username+"]";
			}else{
				sname = value.username;
			}		
			if (sendername.indexOf(";"+sname+";") < 0)
			{				
				users.push(sname);
				userid = value.userid;
				switch(evid){
		//		case "dl_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];
					break;
				case "dl_list_borkers":
					chkall_brokers_states="true";
					G_chkalls[1]=true;
					user[0] = G_brokers_hash[userid];
					break;
				case "dl_list_managers":
					chkall_managers_states="true";
					G_chkalls[1]=true;
					user[0] = G_managers_hash[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";//记录用户全选状态	
							}else{
								chkall_users_states="false";//记录用户全选状态	
							}
							user[0] = G_users_hash[userid];
							change_users_html(user[0].id,value.checked);
							break;
						case "broker":
							if(G_chkalls[1]==true){
								chkall_brokers_states="true";//记录投顾全选状态	
							}else{
								chkall_brokers_states="false";//记录投顾全选状态
							}
							user[0] = G_brokers_hash[userid];
							break;
						case "manager":
							if(G_chkalls[2]==true){
								chkall_managers_states="true";//记录营销全选状态	
							}else{
								chkall_managers_states="false";//记录营销全选状态
							}
							user[0] = G_managers_hash[userid];
							break;
					}
					break;					
				}			
				user[0].selectedStatus = 1;
			}		
		});
		if ($.trim($(txtsenderid).val()).length == 0 || $(txtsenderid).val() == "发送多人时请以英文分号分隔")
		{
			var tmpsendername=users.join(";")+";";
			if(tmpsendername==";"){
				tmpsendername="";
			}
			$(txtsenderid).val(tmpsendername);
		}
		else
		{
			var tmpsendername=users.join(";")+";";
			if(tmpsendername==";"){
				tmpsendername="";
			}
			if(sendername==";"){
				sendername="";
			}else{
				sendername=sendername.substring(1,sendername.length);
			}
			$(txtsenderid).val(sendername  + tmpsendername);
		}
		if ($(txtsenderid).val().length > 0 || $(txtsenderid).val() != "发送多人时请以英文分号分隔")
		{
			$(txtsenderid).css("color","black");
		}
	}
	else
	{
		var removesender = {};
		
		$("#"+evid).find("input").each(function(index,value){
			value.checked = false;
			usertype=$(value).attr("usertype");
			if(usertype=="group"){
				sname = "["+value.username+"]";
			}else{
				sname = value.username;
			}
			
			removesender[sname] = "1";
			//sendername = sendername.replace(";"+sname+";",";");
		
			userid = value.userid;
			switch(evid){
		//		case "dl_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];
					break;
				case "dl_list_borkers":
					chkall_brokers_states="false";//记录投顾全选状态
					G_chkalls[1]=false;
					user[0] = G_brokers_hash[userid];
					break;
				case "dl_list_managers":
					chkall_managers_states="false";//记录营销全选状态
					G_chkalls[2]=false;
					user[0] = G_managers_hash[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";//记录用户全选状态	
							}else{
								chkall_users_states="false";//记录用户全选状态	
							}
							user[0] = G_users_hash[userid];
							change_users_html(user[0].id,value.checked);
							break;
						case "broker":
							if(G_chkalls[1]==true){
								chkall_brokers_states="false";//记录投顾全选状态
							}else{
								chkall_brokers_states="false";//记录投顾全选状态	
							}
							user[0] = G_brokers_hash[userid];
							break;
						case "manager":
							if(G_chkalls[2]==true){
								chkall_managers_states="false";//记录营销全选状态
							}else{
								chkall_managers_states="false";//记录营销全选状态
							}
							user[0] = G_managers_hash[userid];
							break;
					}
					break;
			}		
			user[0].selectedStatus = 0;
		});
		var senderlist = $.trim($(txtsenderid).val()).split(";");
		var newsenderlist = new Array();
		for (var i = 0; i < senderlist.length; i++)
		{
			if (removesender[senderlist[i]]) continue;
			newsenderlist.push(senderlist[i]);
		}
		$(txtsenderid).val(newsenderlist.join(";"));
	}
	getsumnum();
}
/*
*分组排序
*/
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;
}
/*
*发送邮件人员帐号与名称转换
*id:根据名字查询帐号；nm:根据分组名字查询用户名字
*/
function getsender(attr)
{
	var sendlist = {};
	
	var txtsenderid = "#txtSender";
	var sendername = $.trim($(txtsenderid).val()).split(";");
	$(sendername).each(function(index){
		var name = $.trim(sendername[index]);
		if (name =="") return;
		
		if (name=="[全部投顾]") {
			for (var i=0; G_brokers != null && i < G_brokers.length ; i++)
				sendlist[G_brokers[i][attr]] = "1";
			return true;
		}
		
		if (name=="[全部客户经理]") {
			for (var i=0; G_managers != null && i < G_managers.length ; i++)
				sendlist[G_managers[i][attr]] = "1";
			return true;
		} 
		
		if (name=="[全部股民]") {
			for (var i=0; G_users != null && i < G_users.length ; i++)
				sendlist[G_users[i][attr]] = "1";
			return true;
		}
		
		if ((name.indexOf("[")>-1) && (name.indexOf("]")>-1)){
			var 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++){
						var key = null;
						if(attr=="nm"){
							key = G_groupslable[i]["users"][j].name;
						}else{
							key = G_groupslable[i]["users"][j][attr];
						}
						sendlist[key] = "1";
					}
				}
			return true;
		}
		
		if (G_users_hash_name[name]) {
			sendlist[G_users_hash[G_users_hash_name[name]][attr]] = "1";
		} else if (G_brokers_hash_name[name]) {
			sendlist[G_brokers_hash[G_brokers_hash_name[name]][attr]] = "1";
		} else if (G_managers_hash_name[name]) {
			sendlist[G_managers_hash[G_managers_hash_name[name]][attr]] = "1";
		} else {
			sendlist[name] = "1";
		}
	});
	
	var list = new Array();
	for (var id in sendlist)
		list.push(id);
	var senders = list.join(";");
	return senders;
}

/*
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][attr]+ ";");				
					if(yesno < 0)
					{
						Senders += G_brokers[i][attr] + ";";
					}
				}
				return true;
			}else if(name=="[全部客户经理]"){
				for (var i=0; G_managers != null && i < G_managers.length ; i++)
				{
					yesno = Senders.indexOf(";" + G_managers[i][attr]+ ";");				
					if(yesno < 0)
					{
						Senders += G_managers[i][attr] + ";";
					}
				}
				return true;
			}else if(name=="[全部股民]"){
				for (var i=0; G_users != null && i < G_users.length ; i++)
				{
					yesno = Senders.indexOf(";" + G_users[i][attr] + ";");				
					if(yesno < 0)
					{
						Senders += G_users[i][attr]+ ";";
					}
				}
				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][attr] + ";");				
							if(yesno < 0)
							{   
								if(attr=="nm"){
									Senders += G_groupslable[i]["users"][j].name+ ";";
								}else{
									Senders += G_groupslable[i]["users"][j][attr]+ ";";
								}
						
							}
						}
					}
				}
				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;
}
*/

/*
*发送邮件人员帐号与名称转换
*id:根据名字查询帐号；nm:根据分组名字查询用户名字
*/
function getsender_count(attr)
{
	var g_exist=[];
	var count=0;
	var txtsenderid = "#txtSender";
	var Senders = ";";
	var yesno = -1;
	var tmpname="";
	var tmpid="";
	var sendername = $.trim($(txtsenderid).val()).split(";");
	$(sendername).each(function(index){
		var name = $.trim(sendername[index]);
		if (name !="")
		{
			var correctName = false;
			//分组
			if(name=="[全部投顾]"){
				for (var i=0; G_brokers != null && i < G_brokers.length ; i++)
				{
					tmpid=G_brokers[i][attr];
					if (!g_exist[tmpid]){
						count++;
						g_exist[tmpid] = 1;
					}
				}
				correctName = true;
				return true;
			}else if(name=="[全部客户经理]"){
				for (var i=0; G_managers != null && i < G_managers.length ; i++)
				{
					tmpid=G_managers[i][attr];
					if (!g_exist[tmpid]){
						count++;
						g_exist[tmpid] = 1;
					}
				}
				correctName = true;
				return true;
			}else if(name=="[全部股民]"){
				for (var i=0; G_users != null && i < G_users.length ; i++)
				{
					tmpid=G_users[i][attr];
					if (!g_exist[tmpid]){
						count++;
						g_exist[tmpid] = 1;
					}
				}
				correctName = true;
				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++){
							tmpid=G_groupslable[i]["users"][j][attr];
							if (!g_exist[tmpid]){
								count++;
								g_exist[tmpid] = 1;
							}
						}
					}
				}
				correctName = true;
				return true;
			}
			
			//投顾
			if(correctName==false){	
				if(typeof(G_brokers_hash_name[name])!="undefined"){
					tmpid=G_brokers_hash_name[name];
					if (!g_exist[tmpid]){
						count++;
						g_exist[tmpid] = 1;
					}
					correctName = true;	
				}
			}
			//营销
			if(correctName==false){	
				if(typeof(G_managers_hash_name[name])!="undefined"){
					tmpid=G_managers_hash_name[name];
					if (!g_exist[tmpid]){
						count++;
						g_exist[tmpid] = 1;
					}
					correctName = true;	
				}
			}
			//股民
			if(correctName==false){	
				if(typeof(G_users_hash_name[name])!="undefined"){
					tmpid=G_users_hash_name[name];
					if (!g_exist[tmpid]){
						count++;
						g_exist[tmpid] = 1;
					}
					correctName = true;	
				}
			}
			if(correctName == false)
			{
				tmpid=name;
				if (!g_exist[tmpid]){
					count++;
					g_exist[tmpid] = 1;
				}
			}
		}
	});	
	g_exist=null;
	return count;
}
/*
*
*/
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");

}
/*
*获取已选总人数
*/
function getsumnum(){
	var tmpSenders = $("#txtSender").val();	
	if (tmpSenders == "" || tmpSenders =="发送多人时请以英文分号分隔")
	{	
		$("#txtSenderSumNum").val("0");
		$("#txtSenderSumNum").attr("title","已选0人");
		return;
	}else{
		var count = getsender_count("id");
		var tmpsumnum=typeof(count) != "undefined" ? count : "0";
		var tmpsumtitle="已选"+ tmpsumnum +"人";
		$("#txtSenderSumNum").val(tmpsumnum);
		$("#txtSenderSumNum").attr("title",tmpsumtitle);
		
	}
}
/*
*修改内存中的html对象
*/
function change_users_html(id,chk){	
	$("#chk"+id).attr("checked",chk);
}


//利用JavaScript来获取img标签字符串，并替换绝对路径。
function checkimgstrip(html)   
{   
   var tmp = document.createElement("DIV");   
   var imgsize = 0;
   tmp.innerHTML = html; 
   $(tmp).find("img").each(function(){
   	   if(typeof( $(this).attr("data_ue_src")) != "undefined")
   	   {
   	   	   if($(this).attr("data_ue_src").length>0)
   	   	   {
   	   	 		$(this).attr("src",$(this).attr("data_ue_src"));   	   	   
   	   	   }
   	   }
	   if(typeof( $(this).attr("size")) != "undefined")
   	   {
		   if ($(this).attr("size").length >0)
		   {
				imgsize += parseInt($(this).attr("size"));
		   }
   	   }
   });
   total_imgsize = imgsize;
   return  tmp.innerHTML;
}  

//上传文件
function HandleFileButtonClick()
{
	var ifrmDoc = document.getElementById("ifmattach").contentWindow.document;
	userinfo = getSysUser();
	//$("#qsid").val(userinfo[2]);
	//$("#uid").val(userinfo[0]);
	$(ifrmDoc.getElementById("qsid")).val(userinfo[2]);
	$(ifrmDoc.getElementById("uid")).val(userinfo[0]);
	userinfo = null;

	var cd = window.location.href;
	if (cd.lastIndexOf("/") >= 0)
	{
		cd = cd.substring(0,cd.lastIndexOf("/") + 1);
	}
	cd = cd + "cd.htm";
	cd = encodeURIComponent(cd.toLowerCase());
	$(ifrmDoc.getElementById("cburl")).val(cd);
	cd = null;

	var path = $(ifrmDoc.getElementById("upload")).val();
	var filesize = getFileSize(path);
	if (Number(filesize) > G_FILESIZE())
	{
		alert("文件超过上传大小限制");
		return;
	}
	if (Number(filesize) == 0)
	{
		alert("文件为空!");
		return;
	}
	if (Number(filesize) == -1)
	{
		alert("文件被其他程序使用中,无法上传!");
		return;
	}

	var arr=path.split('\\');
	$(ifrmDoc.getElementById("localfilename")).val(arr[arr.length-1]);
	arr  = null;
	path = null;

	$(ifrmDoc.getElementById("frmupload")).attr("action",G_FILESERVICE());
	loadingattach();
	$(ifrmDoc.getElementById("frmupload")).submit();
	ifrmDoc = null;
}

function loadingattach()
{
	$("#attach1").hide();
	$("#attachdel1").hide();
	$("#loadattachtxt").show();
	$("#loadattachpic").show();
	$("#loadattachdel").show();
	$("#attachment").show();
	$("#contentarea").attr("style","height:250px; margin-top:20px;");
	ifrmwrEditor.setHeight(200);
	ifrmwrEditor.body.style.height = "200px";
	if (attachfiles.length > 0)
	{
		$("#attach2").text(attachfiles[attachfiles.length - 1]["localfilename"]);
		$("#attach2").show();
		$("#attachdel2").show();
	}
	else
	{
		$("#attach2").hide();
		$("#attachdel2").hide();
	}
}
//上传回调js
function uploadCallback(o)
{
	var ifrmDoc = document.getElementById("ifmattach").contentWindow.document;
	try{
		var data = decodeURIComponent(o);
		var obj = eval("(" + data + ")");
		if (obj["key"] == "0")
		{
			obj["fullname"] = obj["path"] + obj["filename"];
			var arr = obj["fullname"].split("/");
			arr.pop();
			obj["fullpath"] = arr.join("/");
			obj["localfilename"] = $(ifrmDoc.getElementById("localfilename")).val();
			attachfiles.push(obj);
			reloadattachs();
			$(ifrmDoc.getElementById("cburl")).val("");
			$(ifrmDoc.getElementById("localfilename")).val("");
		}
		else
		{
			alert(obj["text"]);
			reloadattachs();
		}
	}
	catch (e)
	{	
		alert("上传失败！");
	}
	ifrmDoc = null;
}


//清空上传控件
function clearfile()
{
	ifmattach.window.location.reload();
	//var elm = $(document.getElementById("ifmattach").contentWindow.document.getElementById("upload"));
	//elm.after(elm.clone().val(""));  
	//elm.remove();  
}

function attachinsert()
{
	if ($("#loadattachtxt").is(":hidden"))
	{
		clearfile();
		popupDiv('popaddattach');
	}
	else
	{
		alert("您正在上传文件,请先终止上传!");
	}
}

function deleteattach(unindex)
{
	if (unindex == 0)
	{
		clearfile();
		reloadattachs();
	}
	attachfiles.splice(attachfiles.length - unindex,1);
	reloadattachs();
	if (attachfiles.length >0)
	{
		$("#contentarea").attr("style","height:250px; margin-top:20px;");
		ifrmwrEditor.setHeight(200);
		ifrmwrEditor.body.style.height = "200px";
	}
	else
	{
		$("#contentarea").attr("style","height:270px;");
		ifrmwrEditor.setHeight(220);
		ifrmwrEditor.body.style.height = "220px";
	}
}
function reloadattachs()
{
	$("#loadattachtxt").hide();
	$("#loadattachpic").hide();
	$("#loadattachdel").hide();
	/*
	if (attachfiles.length > 2)
	{
		$("#attachmore").show();
	}
	else
	{*/
		$("#attach1").hide();
		$("#attachdel2").hide();
		$("#attach2").hide();
		$("#attachdel2").hide();
		$("#attachmore").hide();
		switch (attachfiles.length)
		{
		case 0:
			$("#attachment").hide();
			hideDiv('popattach');
			$("#contentarea").attr("style","height:270px;");
			ifrmwrEditor.setHeight(220);
			ifrmwrEditor.body.style.height = "220px";
			break;
		default:
			$("#attachmore").show();
		case 2:
			$("#attach2").text(attachfiles[attachfiles.length - 2]["localfilename"]);
			$("#attach2").show();
			$("#attachdel2").show();
			
		case 1:
			$("#attach1").text(attachfiles[attachfiles.length - 1]["localfilename"]);
			$("#attach1").show();
			$("#attachdel1").show();
			$("#attachment").show();
			ifrmwrEditor.setHeight(200);
			ifrmwrEditor.body.style.height = "200px";
			var reverse_attachfiles = attachfiles.reverse();
			$("#attachlist").html($("#attachTemplate").render(reverse_attachfiles));
			reverse_attachfiles = null;
		}
	//}
}

function sendattachfiles(sbody)
{
	var mailbody = "<div id=\"start_content\"";
	total_filesize = 0;
	$.each(attachfiles,function(index,item){
		if (item["size"].indexOf("B") > 0)
		{
			total_filesize += Number(item["size"].replace("B",""));
		}
		else if (item["size"].indexOf("K") > 0)
		{
			total_filesize += Number(item["size"].replace("K","")) * 1024;
		}
		else if (item["size"].indexOf("M") > 0)
		{
			total_filesize += Number(item["size"].replace("M","")) * 1024 * 1024;
		}
	});

	if (attachfiles.length > 0)
	{
		mailbody += " attach='" + encodeURIComponent(JSON.stringify(attachfiles)) + "' ";
	}
	mailbody += ">" + sbody + "</div>";
	return mailbody;
}

//获取附件文件信息;
function getattachfile(sbody)
{
	var strpoint = sbody.indexOf("<div id=\"start_content\" attach='");
	if (strpoint != 0)
	{
		return [];
	}
	var shead = sbody.substring(32);
	if (shead.length <= 0)
	{
		return [];
	}
	strpoint = shead.indexOf("'");
	if (strpoint <= 0)
	{
		return [];
	}
	shead = shead.substring(0,strpoint);
	if (shead.length <= 0)
	{
		return [];
	}
	var data = decodeURIComponent(shead);
	return eval("(" + data + ")");
}

//同步发邮件右侧客户列表收件人
function synval() {
	var d_val = $("#txtSender").val();
	SynchroniseSender(d_val, false);
	getsumnum();
}

//
function editsign()
{
	ifrmSignEditor.setContent(getSign());
	popupDiv('popSign');
}

function saveSign()
{
	var sSign = ifrmSignEditor.getContent();
	saveUserSign(sSign);
	default_content = "<p><br /><br /></p>---------------------------------------------------<br /><div type=\"sign\">" + sSign + "<div><!--end_sign-->";
	var sss = "<div type=\"sign\">";

	var scontent = ifrmwrEditor.getContent();
	var ibegin = scontent.lastIndexOf("<div type=\"sign\">");
	var iend =0;
	if (ibegin >= 0)
	{
		iend = scontent.lastIndexOf("<div><!--end_sign-->");
		if (sSign != "")
		{
			scontent = scontent.substring(0,ibegin + 17) + sSign +  scontent.substring(iend);
		}
		else
		{
			ibegin = scontent.lastIndexOf("---------------------------------------------------");
			if (ibegin >= 0)
			{
				scontent = scontent.substring(0,ibegin) +  scontent.substring(iend + 20);
			}
		}
		ifrmwrEditor.setContent(scontent);
	}
	else
	{
		ifrmwrEditor.setContent(scontent + "<p><br /><br /></p>---------------------------------------------------<br /><div type=\"sign\">" + sSign + "<div><!--end_sign-->")
	}
	hideDiv('popSign');
}

function getSign()
{
	data = getUserSign();
	if (data != null && typeof(data["sign"]) != "undefined" )
	{
		return decodeURIComponent(data["sign"].replace(/\+/g,"%20"));
	}
	else
	{
		return "";
	}
}

/* lujh 2013-3 addvroom */
function hide_allpopup()
{
	$('#divattstock').hide();
	$('#divstockcode').hide();
	$("#div_addvroom").hide();
}

var addvroom_titlemsg = "请输入讲座的标题，字数不超过20个汉字。";
var addvroom_type = 101;

function addvroom()
{
	if (!vroom_isactive()) {
		alert("贵公司尚未开通视频教室的房间，不能为您的客户进行视频讲座，请向乾隆公司进行申请！");
		return;
	}
	var display = $('#div_addvroom').css("display");
	if (display == "" || display == "block") return;
	
	hide_allpopup();
	
	$("#vroom_title").attr("value", addvroom_titlemsg).css("color","gray");
	$("#vroom_date").attr("value", "");
	$("#div_addvroom select").each(function() {
			$(this)[0].selectedIndex = 0;
		});
	$('#div_addvroom').show();
}

function addvroom_close()
{
	$('#div_addvroom').hide();
	$('#divattstock').hide();
}

function vroom_add()
{
	var title = $("#vroom_title").attr("value");
	if (title == addvroom_titlemsg || title == "") {
		alert("请输入标题");
		$("#vroom_title").focus();
		return;
	}
	
	var date = $("#vroom_date").attr("value");
	if (date == "")
	{
		alert("请输入日期");
		$("#vroom_date").focus();
		return;
	}
	if (!(/^\d{4}-\d{1,2}-\d{1,2}$/.test(date)))
	{
		alert("日期的格式必须为yyyy-mm-dd");
		$("#vroom_date").focus();
	}
	date = new Date(date.replace(/\-/g, "\/"));
	date = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
	
	var startdate = date + " " + $("#vroom_s_hour option:selected" ).text() + ":" + $("#vroom_s_minute option:selected" ).text() + ":00";
	startdate = new Date(startdate.replace(/\-/g, "\/"));
	if (startdate.getTime() < (new Date()).getTime())
	{
		alert("开始时间必须大于当前时间");
		$("#vroom_s_hour").focus();
		return;
	}

	var stime = $("#vroom_s_hour option:selected" ).text() + $("#vroom_s_minute option:selected" ).text();
	var etime = $("#vroom_e_hour option:selected" ).text() + $("#vroom_e_minute option:selected" ).text();
	if (parseInt(etime) <= parseInt(stime))
	{
		alert("结束时间必须大于开始时间");
		$("#vroom_e_hour").focus();
		return;
	}
	
	html_vroom = '&nbsp;<input id="button#ID#" type="button"'
		+ ' style="font-size:12px; font-family:\'宋体\'; cursor:pointer; height:19px; _margin-bottom:1px;border:1px solid #9fb3ca; background:url(img/ss_mail_icon6.gif) left top repeat-x;"'
		+ ' title="' + title.replace(/"/g, "'") + '" date="' + date + '" stime="' + stime + '" etime="' + etime + '"'
		+ ' mytype=#TYPE# onclick="javascript:vroom_show(this);oop(#TYPE#);ooop(#ID#);return false;" value = "视频讲座"/>&nbsp;';
	var data = AddMailAttach(NewEmailSeq,"101\r\n"+ title);
	if( data < 0)
	{
		alert("添加视频讲座失败");
	}
	else if (data > 0)
	{
		addvroom_close();
	}
}

function vroom_title_onfocus()
{
	var input = $("#vroom_title");
	if (input.attr("value") == addvroom_titlemsg)
	{
		input.attr("value", "").css("color", "black");
	}
}

function vroom_title_onblur()
{
	var input = $("#vroom_title");
	if (input.attr("value") == "")
	{
		input.attr("value", addvroom_titlemsg).css("color","gray");
	}
}
