// JavaScript Document
var itab = "Inbox";
var version = "";

var statusInbox = {};
statusInbox["MailTotal"] = 0;
statusInbox["PageTotal"] = 1;
statusInbox["tmpPageTotal"] = 0;
statusInbox["PageLast"] = 0;//判断是不是跳转到最后一页
statusInbox["CurPage"] = 1;
statusInbox["filter"] = "";//收件箱搜索条件
statusInbox["UnreadMailTotal"]=0;//收件箱未读邮件数量
var statusSent = {};
statusSent["MailTotal"] = 0;
statusSent["PageTotal"] = 1;
statusSent["tmpPageTotal"] = 0;
statusSent["PageLast"] = 0;//判断是不是跳转到最后一页
statusSent["CurPage"] = 1;
statusSent["filter"] = "";//发件箱搜索条件
var Odata;
var datainfo=[];//返回当前邮件回执信息
var saveCustomDataKeyName="qlmaicustomerdatakey";//保存当前经纪人下所有用户信息key值
var G_MailList_hash_index=[];//邮件列表缓存数据var G_MailList_hash_index【本地邮件编号】=发件箱邮件索引信息;
function showReceiveMail()
{
	reflashmaillist();
	goPage(statusInbox["CurPage"],"Inbox");
	goPage(statusSent["CurPage"],"Sent");
}

function MarkRead(seq)
{
	var text = GetMail(seq);
	var iFirstContent = text.indexOf("<content><![CDATA[");
	var iLastContent = text.lastIndexOf("]]></content>");
	if ((iFirstContent < 0 ) || (iLastContent < 0))
	{
		return;
	}
	var sbody = 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 sattr = "000000" + parseFloat($($(xml).find("mail")[0]).attr("attrib")).toString(16);
	sattr = sattr.substring(sattr.length-6,sattr.length);
	sattr = parseFloat(sattr.substring(1,2)).toString(2);
	if (sattr.substring(sattr.length -2,sattr.length -1) != "1")
	{
		SetAttrib(seq + "\r\n65536");
	}
	else
	{
		SetAttrib(seq + "\r\n196608");
	}
	var srvseq = $($(xml).find("mail")[0]).attr("srvseq");
	if(srvseq==undefined)
	{
		srvseq="";
	}
	var sfrom = $($(xml).find("from")[0]).text();
	var tmpparam=srvseq+"|"+sfrom+"|0";
	WriteReceipt(tmpparam);//回执
}

function MailDelete(seq)
{
	statusInbox["tmpPageTotal"] = statusInbox["PageTotal"] ;
	statusSent["tmpPageTotal"] = statusSent["PageTotal"];
	DeleteMail(seq);
	reflashmaillist();	
	if (statusInbox["PageLast"] == 1)
	{
		statusInbox["PageLast"] = 0;
		maildeleinfo("Inbox");
		
	}
	else
	{
		goPage(statusInbox["CurPage"],"Inbox");
	}
	
	if (statusSent["PageLast"] == 1)
	{
		statusSent["PageLast"] = 0;
		maildeleinfo("Sent");
	}
	else
	{
		goPage(statusSent["CurPage"],"Sent");
	}
	
}
//test
function maildeleinfo(stab)
{
	var ipage =0;
	if (stab == "Inbox")
	{
		ipage=statusInbox["CurPage"];
		$("#li_Inbox_1").attr("class","mail_pagesNormal");
		$("#li_Inbox_2").attr("class","mail_pagesNormal");
		$("#li_Inbox_3").attr("class","mail_pagesNormal");
		if (statusInbox["PageTotal"] > 3)
		{		
			$("#li_Inbox_1").attr("pageIndex",(ipage - 2).toString());
			$("#li_Inbox_1 a").text((ipage - 2).toString());
			$("#li_Inbox_2").attr("pageIndex",(ipage-1).toString());
			$("#li_Inbox_2 a").text((ipage-1).toString());
			$("#li_Inbox_3").attr("pageIndex",ipage.toString());
			$("#li_Inbox_3 a").text(ipage.toString());
			$("#li_Inbox_3").attr("class","mail_pagesAction");		
		}
		else if (statusInbox["PageTotal"] == 3)
		{
			$("#Inbox_foot").show();
			$("#li_Inbox_first").hide();
			$("#li_Inbox_1").show();
			$("#li_Inbox_1").attr("pageIndex","1");
			$("#li_Inbox_1").attr("tab","Inbox");
			$("#li_Inbox_1 a").text("1");
			$("#li_Inbox_2").show();
			$("#li_Inbox_2").attr("pageIndex","2");
			$("#li_Inbox_2").attr("tab","Inbox");
			$("#li_Inbox_2 a").text("2");
			$("#li_Inbox_3").show();
			$("#li_Inbox_3").attr("pageIndex","3");
			$("#li_Inbox_3").attr("tab","Inbox");
			$("#li_Inbox_3 a").text("3");
			$("#li_Inbox_last").hide();
			$("#li_Inbox_" + ipage.toString()).attr("class","mail_pagesAction");
		}
		else if (statusInbox["PageTotal"] == 2)
		{
			$("#Inbox_foot").show();
			$("#li_Inbox_first").hide();
			$("#li_Inbox_1").show();
			$("#li_Inbox_1").attr("pageIndex","1");
			$("#li_Inbox_1").attr("tab","Inbox");
			$("#li_Inbox_1 a").text("1");
			$("#li_Inbox_2").show();
			$("#li_Inbox_2").attr("pageIndex","2");
			$("#li_Inbox_2").attr("tab","Inbox");
			$("#li_Inbox_2 a").text("2");
			$("#li_Inbox_3").hide();
			$("#li_Inbox_last").hide();
			$("#li_Inbox_" + ipage.toString()).attr("class","mail_pagesAction");
		}
		else if (statusInbox["PageTotal"] == 1)
		{
			$("#Inbox_foot").show();
			$("#li_Inbox_first").hide();
			$("#li_Inbox_1").show();
			$("#li_Inbox_1").attr("pageIndex","1");
			$("#li_Inbox_1").attr("tab","Inbox");
			$("#li_Inbox_1 a").text("1");
			$("#li_Inbox_2").hide();
			$("#li_Inbox_3").hide();
			$("#li_Inbox_last").hide();
			$("#li_Inbox_" + ipage.toString()).attr("class","mail_pagesAction");	
		}
		else
		{
			$("#Inbox_foot").hide();
		}
	
	}
	else
	{
		ipage=parseInt(statusSent["CurPage"]);
		$("#li_Sent_1").attr("class","mail_pagesNormal");
		$("#li_Sent_2").attr("class","mail_pagesNormal");
		$("#li_Sent_3").attr("class","mail_pagesNormal");
//		if (statusSent["PageTotal"] <= 3)
//		{
//			$("#li_Sent_" + ipage.toString()).attr("class","mail_pagesAction");
//		}
		if (statusSent["PageTotal"] > 3)
		{
				$("#li_Sent_1").attr("pageIndex",(ipage - 2).toString());
				$("#li_Sent_1 a").text((ipage - 2).toString());
				$("#li_Sent_2").attr("pageIndex",(ipage-1).toString());
				$("#li_Sent_2 a").text((ipage-1).toString());
				$("#li_Sent_3").attr("pageIndex",ipage.toString());
				$("#li_Sent_3 a").text(ipage.toString());
				$("#li_Sent_3").attr("class","mail_pagesAction");				
		}
		else if (statusSent["PageTotal"] == 3)
		{
			$("#Sent_foot").show();
			$("#li_Sent_first").hide();
			$("#li_Sent_1").show();
			$("#li_Sent_1").attr("pageIndex",1);
			$("#li_Sent_1").attr("tab","Sent");
			$("#li_Sent_1 a").text("1");
			$("#li_Sent_2").show();
			$("#li_Sent_2").attr("pageIndex",2);
			$("#li_Sent_2").attr("tab","Sent");
			$("#li_Sent_2 a").text("2");
			$("#li_Sent_3").show();
			$("#li_Sent_3").attr("pageIndex",3);
			$("#li_Sent_3").attr("tab","Sent");
			$("#li_Sent_3 a").text("3");
			$("#li_Sent_last").hide();
			$("#li_Sent_" + ipage.toString()).attr("class","mail_pagesAction");
		}
		else if (statusSent["PageTotal"] == 2)
		{
			$("#Sent_foot").show();
			$("#li_Sent_first").hide();
			$("#li_Sent_1").show();
			$("#li_Sent_1").attr("pageIndex",1);
			$("#li_Sent_1").attr("tab","Sent");
			$("#li_Sent_1 a").text("1");	
			$("#li_Sent_2").show();
			$("#li_Sent_2").attr("pageIndex",2);
			$("#li_Sent_2").attr("tab","Sent");
			$("#li_Sent_2 a").text("2");
			$("#li_Sent_3").hide();
			$("#li_Sent_last").hide();
			$("#li_Sent_" + ipage.toString()).attr("class","mail_pagesAction");
		}
		else if (statusSent["PageTotal"] == 1)
		{
			$("#Sent_foot").show();
			$("#li_Sent_first").hide();
			$("#li_Sent_1").show();
			$("#li_Sent_1").attr("pageIndex",1);
			$("#li_Sent_1").attr("tab","Sent");
			$("#li_Sent_1 a").text("1");
			$("#li_Sent_2").hide();
			$("#li_Sent_3").hide();
			$("#li_Sent_last").hide();
			$("#li_Sent_" + ipage.toString()).attr("class","mail_pagesAction");
		}
		else
		{
			$("#Sent_foot").hide();
		}
	}
	goPage(ipage,stab);
	
}

function changepage(elm)
{
	var ipage = Number($("#" + elm).attr("pageIndex"));
	var stab = $("#" + elm).attr("tab");
	if (stab == "Inbox")
	{
		if (statusInbox["CurPage"] == ipage)
		{
			return;
		}
		$("#li_Inbox_1").attr("class","mail_pagesNormal");
		$("#li_Inbox_2").attr("class","mail_pagesNormal");
		$("#li_Inbox_3").attr("class","mail_pagesNormal");
		if (statusInbox["PageTotal"] <= 3)
		{
			$("#li_Inbox_" + ipage.toString()).attr("class","mail_pagesAction");
		}
		else
		{
			switch (elm)
			{
			case "li_Inbox_1":
				if (ipage > 1)
				{
					$("#li_Inbox_1").attr("pageIndex",(ipage - 1).toString());
					$("#li_Inbox_1 a").text((ipage - 1).toString());
					$("#li_Inbox_2").attr("pageIndex",(ipage).toString());
					$("#li_Inbox_2 a").text(ipage.toString());
					$("#li_Inbox_3").attr("pageIndex",(ipage + 1).toString());
					$("#li_Inbox_3 a").text((ipage + 1).toString());
					$("#li_Inbox_2").attr("class","mail_pagesAction");
				}
				else
				{
					$("#" + elm).attr("class","mail_pagesAction");
				}
				break;
			case "li_Inbox_2":
				if (ipage > 1)
				{
					$("#li_Inbox_1").attr("pageIndex",(ipage - 1).toString());
					$("#li_Inbox_1 a").text((ipage - 1).toString());
					$("#li_Inbox_2").attr("pageIndex",(ipage).toString());
					$("#li_Inbox_2 a").text(ipage.toString());
					$("#li_Inbox_3").attr("pageIndex",(ipage + 1).toString());
					$("#li_Inbox_3 a").text((ipage + 1).toString());
					$("#li_Inbox_2").attr("class","mail_pagesAction");
				}
				else
				{
					$("#" + elm).attr("class","mail_pagesAction");
				}
				break;
			case "li_Inbox_3":
				if (ipage < statusInbox["PageTotal"])
				{
					$("#li_Inbox_1").attr("pageIndex",(ipage - 1).toString());
					$("#li_Inbox_1 a").text((ipage - 1).toString());
					$("#li_Inbox_2").attr("pageIndex",(ipage).toString());
					$("#li_Inbox_2 a").text(ipage.toString());
					$("#li_Inbox_3").attr("pageIndex",(ipage + 1).toString());
					$("#li_Inbox_3 a").text((ipage + 1).toString());
					$("#li_Inbox_2").attr("class","mail_pagesAction");
				}
				else
				{
					$("#" + elm).attr("class","mail_pagesAction");
				}
				break;
			}
		}
	}
	else
	{
		if (statusSent["CurPage"] == ipage)
		{
			return;
		}
		$("#li_Sent_1").attr("class","mail_pagesNormal");
		$("#li_Sent_2").attr("class","mail_pagesNormal");
		$("#li_Sent_3").attr("class","mail_pagesNormal");
		if (statusSent["PageTotal"] <= 3)
		{
			$("#li_Sent_" + ipage.toString()).attr("class","mail_pagesAction");
		}
		else
		{
			switch (elm)
			{
			case "li_Sent_1":
				if (ipage > 1)
				{
					$("#li_Sent_1").attr("pageIndex",(ipage - 1).toString());
					$("#li_Sent_1 a").text((ipage - 1).toString());
					$("#li_Sent_2").attr("pageIndex",(ipage).toString());
					$("#li_Sent_2 a").text(ipage.toString());
					$("#li_Sent_3").attr("pageIndex",(ipage + 1).toString());
					$("#li_Sent_3 a").text((ipage + 1).toString());
					$("#li_Sent_2").attr("class","mail_pagesAction");
				}
				else
				{
					$("#" + elm).attr("class","mail_pagesAction");
				}
				break;
			case "li_Sent_2":
				if (ipage > 1)
				{
					$("#li_Sent_1").attr("pageIndex",(ipage - 1).toString());
					$("#li_Sent_1 a").text((ipage - 1).toString());
					$("#li_Sent_2").attr("pageIndex",(ipage).toString());
					$("#li_Sent_2 a").text(ipage.toString());
					$("#li_Sent_3").attr("pageIndex",(ipage + 1).toString());
					$("#li_Sent_3 a").text((ipage + 1).toString());
					$("#li_Sent_2").attr("class","mail_pagesAction");
				}
				else
				{
					$("#" + elm).attr("class","mail_pagesAction");
				}
				break;
			case "li_Sent_3":
				if (ipage < statusSent["PageTotal"])
				{
					$("#li_Sent_1").attr("pageIndex",(ipage - 1).toString());
					$("#li_Sent_1 a").text((ipage - 1).toString());
					$("#li_Sent_2").attr("pageIndex",(ipage).toString());
					$("#li_Sent_2 a").text(ipage.toString());
					$("#li_Sent_3").attr("pageIndex",(ipage + 1).toString());
					$("#li_Sent_3 a").text((ipage + 1).toString());
					$("#li_Sent_2").attr("class","mail_pagesAction");
				}
				else
				{
					$("#" + elm).attr("class","mail_pagesAction");
				}
				break;
			}
		}
	}
	goPage(ipage,stab);
}

function ReadMailDetail(i,stab)
{
	if (typeof(Odata["a" + stab][i]["mailsource"]) == "undefined" || Odata["a" + stab][i]["mailsource"] == "")
	{
		var text = GetMail(Odata["a" + stab][i]["seq"]);
		Odata["a" + stab][i]["mailsource"] = text;
		var iFirstContent = text.indexOf("<content><![CDATA[");
		var iLastContent = text.lastIndexOf("]]></content>");
		var sbody = text.substring(iFirstContent + 18,iLastContent);
//		var tmp = document.createElement("DIV");
//		tmp.innerHTML = sbody; 
//		$(tmp).find("input").each(function(){
//		   if ($(this).attr("disabled") != "disabled")
//		   {
//			   switch ($(this).attr("mytype"))
//			   {
//				   case "4":
//						Odata["a" + stab][i]["type4"] = true;
//				   break;
//				   case "2":
//						Odata["a" + stab][i]["type2"] = true;
//				   break;
//				   case "3":
//						Odata["a" + stab][i]["type3"] = true;
//				   break;
//				   case "1":
//						Odata["a" + stab][i]["type1"] = true;
//				   break;
//			   }
//		   }
//		});
//		tmp = null;
		var sRight = "";
		for (key in G_Rights)
		{
			Odata["a" + stab][i][key] = false;
		}
		if ((iFirstContent < 0 ) || (iLastContent < 0))
		{
			Odata["a" + stab][i]["timestamp"] = "";
			Odata["a" + stab][i]["type"] = "";
			Odata["a" + stab][i]["title"] = "邮件接收错误";
			Odata["a" + stab][i]["to"] = "";
			Odata["a" + stab][i]["fromName"] = "";
			Odata["a" + stab][i]["toName"] = "";
			Odata["a" + stab][i]["TypeAndRight"]="";

		}
		else
		{
			//去除邮件正文
			text = text.substring(0,iFirstContent) + "<content></content>" + text.substring(iLastContent + 13,text.length);
			var xml = ql_xml_stringtoxml(text.replace(/\r/g, ""));
			Odata["a" + stab][i]["timestamp"] = $($(xml).find("mail")[0]).attr("timestamp");
			Odata["a" + stab][i]["type"] = $($(xml).find("type")[0]).attr("no");
			var stitle = decodeString($($(xml).find("title")[0]).text());
			Odata["a" + stab][i]["title"] = html_encode(stitle);
			
			if (Odata["a" + stab][i]["type"] == "4")
			{
				Odata["a" + stab][i]["goldcode"] = $($(xml).find("goldcode")[0]).text();
			}
			Odata["a" + stab][i]["to"] = $($(xml).find("to")[0]).text();
			Odata["a" + stab][i]["from"]=$($(xml).find("from")[0]).text();
			var sfromname = Odata["a" + stab][i]["from"].toLowerCase();
			//获取附件及权限类型
			Odata["a" + stab][i]["TypeAndRight"]="";
			var tmptypeandright=$($(xml).find("type")[0]).attr("subno");
			if(tmptypeandright != undefined && tmptypeandright != "")
			{
				Odata["a" + stab][i]["TypeAndRight"]=tmptypeandright;
			}
			//获取发件人中文名称
			var tmpsfromname=$($(xml).find("from")[0]).attr("name");
			Odata["a" + stab][i]["fromName"]="";
			
			if(tmpsfromname != undefined && tmpsfromname != "")
			{
				Odata["a" + stab][i]["fromName"] = tmpsfromname;
			}

			//获取收件人中文名称	
			Odata["a" + stab][i]["toName"] = "";
			var Tos = Odata["a" + stab][i]["to"].split(";");
			var tmpstoName=$($(xml).find("to")[0]).attr("name");	
			if(tmpstoName != undefined && tmpstoName != "")
			{
				stoName = tmpstoName;
				Odata["a" + stab][i]["toName"] = tmpstoName;
			}
			//发件箱获取当前邮件已读人数
			if(stab=="Sent")
			{
				Odata["a" + stab][i]["retlistnum"]=	GetReturnListNumber(Odata["a" + stab][i]["seq"]);		
			}
			var tmpattacthmentnum = getattachfile(sbody);
			if(tmpattacthmentnum =="0")
			{
				Odata["a" + stab][i]["attacthment"]="true";
			}else{
				Odata["a" + stab][i]["attacthment"]="false";
			}
			
			//获取索取邮件类型
			var tmpproducttype=$($(xml).find("producttype")[0]).attr("no");
			if (typeof(tmpproducttype) == "undefined" || tmpproducttype=="" )
			{
				Odata["a" + stab][i]["producttype"]="0";
			}else{
				Odata["a" + stab][i]["producttype"]=tmpproducttype;
			}
			//获取产品中心赋权邮件类型产品类型
			var tmptypeproducttype=$($(xml).find("type")[0]).attr("prodtype");
			if (typeof(tmptypeproducttype) == "undefined" || tmptypeproducttype=="" )
			{
				Odata["a" + stab][i]["TypeAndRightAndProd"]="0";//兼容老版本
			}else{
				Odata["a" + stab][i]["TypeAndRightAndProd"]=tmptypeproducttype;
			}
		}
	}
}

//获取附件文件信息;
function getattachfile(sbody)
{
	var strpoint = sbody.indexOf("<div id=\"start_content\" attach='");
	return strpoint;
}
//根据notice 触发更新已发阅读人数数组
function changeMailDetail(seq)
{
	var length=	Odata["aSent"].length;
	for(var i=length-1;i>=0;i--)
	{
		if(Odata["aSent"][i]["seq"]==seq)
		{
			Odata["aSent"][i]["retlistnum"]=GetReturnListNumber(seq);			
			$("#hover_Sent li div font").each(function()
			{			
				if($(this).attr("seq")==seq)
				{			
					$(this).text(Odata["aSent"][i]["retlistnum"]+"人");
					return;
				}
			});
			break;
		}
	}
}
function goPage(pageIndex,stab)
{
	var sdetails = [];
	var iCurPage = pageIndex;
	if (stab == "Inbox")
	{
		if (pageIndex > statusInbox["PageTotal"] )
		{
			iCurPage = statusInbox["PageTotal"];
		}
		statusInbox["CurPage"] = iCurPage;
	}
	else
	{
		if (pageIndex > statusSent["PageTotal"])
		{
			iCurPage = statusSent["PageTotal"];
		}
		statusSent["CurPage"] = iCurPage;
	}
	if (iCurPage < 1)
	{
		iCurPage = 1;
	}
//	var aContact = [];
	var version = GetVersion();
//	var brokersData	= {};
//	var customerData = {};
//	switch (version)
//	{
//		case "0":
//			brokersData = load_BrokerData("2");
//			aContact = brokersData;
//			break;
//		case "1":
//			customerData=load_CustomerData("2","","");
//			aContact = customerData;
//			break;
//	}	
	for (var i=(iCurPage - 1) * 10 ; Odata["a" + stab] && i<(Odata["a" + stab].length < iCurPage * 10 ? Odata["a" + stab].length : iCurPage * 10) ; i++ )
	{
		ReadMailDetail(i,stab);
	//	ReadMailDetail(i,stab,aContact);
		var sfrom = Odata["a" + stab][i]["from"];
		var stimestamp = Odata["a" + stab][i]["timestamp"];
		var stitle = Odata["a" + stab][i]["title"];
		var unreadClass = "";
		if ( Odata["a" + stab][i]["unread"] == "1")
		{
			unreadClass = " style=\"font-weight:bold; color:#4d4d4d;\"";//未读
		}
		else
		{
			unreadClass = "";//已读
		}
		var sbox = "";
		var sname = "";
		if (stab == "Inbox")
		{
			sbox = "发件人";
			if(Odata["a" + stab][i]["fromName"]=="")
			{
				sname= Odata["a" + stab][i]["from"]
			}
			else
			{
				sname = Odata["a" + stab][i]["fromName"];
			}
		}
		else
		{
			sbox = "收件人";
			if(Odata["a" + stab][i]["toName"]=="")
			{
				sname = Odata["a" + stab][i]["to"];
			}
			else
			{
				sname = Odata["a" + stab][i]["toName"];
			}
			
		}
		
		
		//sdetails.push("<li onclick=\"javascript:OpenMailPOP('" + Odata["a" + stab][i]["seq"] + "','" + stab + "',this," + i.toString() + ");return false;\"><h1 title=\""+ sname +"\" style=\" width:110px; height:20px; white-space:nowarp; overflow:hidden; text-overflow:ellipsis;word-wrap:break-word;word-break:break-all; \">" + sbox + "：<a href=\"#\" target=\"_blank\" onclick=\"return false;\">" + sname + "</a></h1><h2 d=d style=\"cursor:pointer;display:none\" onclick=\"javascript:MailDelete('"+ Odata["a" + stab][i]["seq"] + "');stopBubble(event);return false;\">删除</h2><h2 v=v style=\"cursor:pointer;\">" + getDateDiff(stimestamp) + "</h2>");		
		if(i%2==0)
		{
			sdetails.push("<li id=\"li_"+ Odata["a" + stab][i]["seq"] +"\" onmousedown=\"javascript:if (window.event.button==1) OpenMailPOP('" + Odata["a" + stab][i]["seq"] + "','" + stab + "',this," + i.toString() + ");return false;\">");
		}
		else
		{
			sdetails.push("<li  id=\"li_"+ Odata["a" + stab][i]["seq"] +"\"  style=\"background:#e7f3fe;\" onmousedown=\"javascript:if (window.event.button==1) OpenMailPOP('" + Odata["a" + stab][i]["seq"] + "','" + stab + "',this," + i.toString() + ");return false;\">");		
		}			
		sdetails.push("<h1 title=\""+ sname +"\" style=\" width:128px; height:20px; white-space:nowarp; overflow:hidden; text-overflow:ellipsis;word-wrap:break-word;word-break:break-all; \">" + sbox + "：<a href=\"#\" target=\"_blank\" onclick=\"return false;\">" + sname + "</a></h1><h2 d=d style=\"cursor:pointer;display:none\" onmousedown=\"javascript:MailDelete('"+ Odata["a" + stab][i]["seq"] + "');stopBubble(event);return false;\">删除</h2><h2 v=v style=\"cursor:pointer;\">" + getDateDiff(stimestamp) + "</h2>");
		sdetails.push("<p title=\"" + stitle + "\" onclick=\"javascript:return false;\">");
		sdetails.push(" <span" + unreadClass + " style=\"word-wrap:break-word;word-break:break-all;\">标题：" + stitle + "</span> ");
		var tmpattacthment=Odata["a" + stab][i]["attacthment"];	
		if(tmpattacthment=="true"){
			sdetails.push(" <font title=\"附件\"></font>");//附件图标显示
		}
		sdetails.push("</p>");
		sdetails.push("<span class=\"icon\">");
		
		//加载图片类型 增加产品中心图片显示 
		var tmpTypeAndRightProd=Odata["a" + stab][i]["TypeAndRightAndProd"];
		if(tmpTypeAndRightProd < 60)//自有类型权限图标显示（2：短期权限，3：试用产品 0：兼容老版本）
		{
			var tmpTypeAndRight=Odata["a" + stab][i]["TypeAndRight"].split(",");
			if(tmpTypeAndRight.length >0)
			{
				for(var j=0;j<tmpTypeAndRight.length;j++)
				{
					if(tmpTypeAndRight[j] !="")
					{
						sdetails.push("<img src=\"img/" + tmpTypeAndRight[j] + ".gif\" />"); 
					}
				}
			}
		}else{//产品中心自定义类型展现（60办公类 61投顾类 62资讯类 63理财类）
			sdetails.push("<img src=\"img/" + tmpTypeAndRightProd + ".gif\"  style=\"width:71px;height:25px\"/>"); 		
		}
			
		sdetails.push("</span>");
		if(version == "1")//判断经纪人显示已读人数
		{
			//当前邮件已读人数
			if (stab == "Sent")
			{
				var retlistnum = Odata["a" + stab][i]["retlistnum"];		
				sdetails.push("<div class=\"read_num clear\">已读客户：<font onmousedown=\"javascript:if (window.event.button==1) OpenMailReturnList('"+ i +"'); window.event.cancelBubble = true;\" seq=\""+ Odata["a" + stab][i]["seq"] +"\">"+ retlistnum +"人</font></div>");		
			}
		}
		sdetails.push("</li>");
	}
	
	if(sdetails.length ==0)
	{	
		sdetails.push("	<li>");
		sdetails.push("	<h1><span style=\" font-size: 15px; algin:center;\"><font color=\"#808080\">当前列表无邮件信息</font></span></h1>");
		sdetails.push("	</li>");
	}
	$("#hover_" + stab).html("<ul>" + sdetails.join("") + "</ul>");
	$("#hover_" + stab + " li").hover(
		function(){
			//$(this).find('h2[d=d]').html("删除").css("cursor","pointer").fadeIn(600);
			$(this).find('h2[d=d]').show();
			$(this).find('h2[v=v]').hide();
			//$(this).css("background","#e4f5ff");
		},
		function(){
			//$(this).find('h2[v=v]').html($(this).attr("v")).fadeIn(300);
			$(this).find('h2[d=d]').hide();
			$(this).find('h2[v=v]').show();
			//$(this).css("background","");
		}
	  )
}

function PageFirst(stab)
{
	$("#li_" + stab + "_1").attr("class","mail_pagesAction");
	$("#li_" + stab + "_2").attr("class","mail_pagesNormal");
	$("#li_" + stab + "_3").attr("class","mail_pagesNormal");
	$("#li_" + stab + "_1").attr("pageIndex","1");
	$("#li_" + stab + "_2").attr("pageIndex","2");
	$("#li_" + stab + "_3").attr("pageIndex","3");
	$("#li_" + stab + "_1 a").text("1");
	$("#li_" + stab + "_2 a").text("2");
	$("#li_" + stab + "_3 a").text("3");
	goPage(1,stab);
}

function  PageLast(stab)
{
	$("#li_" + stab + "_1").attr("class","mail_pagesNormal");
	$("#li_" + stab + "_2").attr("class","mail_pagesNormal");
	$("#li_" + stab + "_3").attr("class","mail_pagesAction");
	if (stab == "Inbox")
	{
		$("#li_" + stab + "_1").attr("pageIndex",(statusInbox["PageTotal"] - 2).toString());
		$("#li_" + stab + "_1 a").text((statusInbox["PageTotal"] - 2).toString());
		$("#li_" + stab + "_2").attr("pageIndex",(statusInbox["PageTotal"] - 1).toString());
		$("#li_" + stab + "_2 a").text((statusInbox["PageTotal"] - 1).toString());
		$("#li_" + stab + "_3").attr("pageIndex",statusInbox["PageTotal"].toString());
		$("#li_" + stab + "_3 a").text(statusInbox["PageTotal"].toString());
		goPage(statusInbox["PageTotal"],stab)
	}
	else
	{
		$("#li_" + stab + "_1").attr("pageIndex",(statusSent["PageTotal"] - 2).toString());
		$("#li_" + stab + "_1 a").text((statusSent["PageTotal"] - 2).toString());
		$("#li_" + stab + "_2").attr("pageIndex",(statusSent["PageTotal"] - 1).toString());
		$("#li_" + stab + "_2 a").text((statusSent["PageTotal"] - 1).toString());
		$("#li_" + stab + "_3").attr("pageIndex",statusSent["PageTotal"].toString());
		$("#li_" + stab + "_3 a").text(statusSent["PageTotal"].toString());
		goPage(statusSent["PageTotal"],stab)
	}
}

function ListMail(stab)
{
	var sdetails = "";
	var iCurPage = 1;
	/*
	if (Odata["a" + stab].length > 0)
	{
		$("#" + stab + "_middle").show();
	}
	else
	{
		$("#" + stab + "_middle").hide();
	}
	*/
	if (stab == "Inbox")
	{
		if (statusInbox["filter"] != ""|| selectusers!="")
		{
			for (var i=0; Odata["a" + stab] && i < Odata["a" + stab].length; i++)
			{
				ReadMailDetail(i,stab);
			//	ReadMailDetail(i,stab,aContact);
			}		
			if (statusInbox["filter"] != "")
			{		
				Odata["a" + stab] =  $.grep(Odata["a" + stab],function(val,key){
					return (val["title"].toLowerCase().indexOf(statusInbox["filter"].toLowerCase()) >= 0) || 
							(val["from"].toLowerCase().indexOf(statusInbox["filter"].toLowerCase()) >= 0) || 
							(val["to"].toLowerCase().indexOf(statusInbox["filter"].toLowerCase()) >= 0) ||
							(val["fromName"].toLowerCase().indexOf(statusInbox["filter"].toLowerCase()) >= 0) ||
							(val["toName"].toLowerCase().indexOf(statusInbox["filter"].toLowerCase()) >= 0);						
				});
			}
			if(selectusers!="")
			{
				Odata["a" + stab] =  $.grep(Odata["a" + stab],function(val,key){
					var a_selectusers = selectusers.split(";");
					var filterto = false;
					$.each(a_selectusers,function(index,v) {
						if (val["from"].toLowerCase().indexOf(v) >=0)
						{
							filterto = true;
							return;
						}
					});
					return (selectusers.toLowerCase().indexOf(val["from"].toLowerCase()) >= 0) || filterto;
				});
			}
		}
		statusInbox["MailTotal"] = Odata["a" + stab].length;
		statusInbox["PageTotal"] = Math.ceil(statusInbox["MailTotal"] / 10);
		iCurPage = statusInbox["CurPage"];	
		if(statusInbox["CurPage"] > statusInbox["PageTotal"] && statusInbox["PageTotal"] > 0)
		{	
			statusInbox["CurPage"] = statusInbox["PageTotal"];
			statusInbox["PageLast"] = 1;
		}	
		if(statusInbox["tmpPageTotal"] > statusInbox["PageTotal"] && statusInbox["CurPage"] == statusInbox["PageTotal"])
		{
			statusInbox["PageLast"] = 1;
		}
		//	$("#InboxNum").text(statusInbox["MailTotal"].toString());//收件箱总邮件数量
		if(Odata["iindexUnRead"] != "" && Odata["iindexUnRead"] > 0)
		{
			statusInbox["UnreadMailTotal"]=Odata["iindexUnRead"];
		}
		else
		{
			statusInbox["UnreadMailTotal"]=0;
		}
		$("#InboxNum").text(statusInbox["UnreadMailTotal"].toString());//收件箱总邮件数量
	
	}
	else
	{
		if (statusSent["filter"] != ""|| selectusers!="")
		{		
			for (var i=0; Odata["a" + stab] && i < Odata["a" + stab].length; i++)
			{
			//	ReadMailDetail(i,stab,aContact);
				ReadMailDetail(i,stab);
			}
			if (statusSent["filter"] != "")
			{			
				Odata["a" + stab] =  $.grep(Odata["a" + stab],function(val,key){
					return (val["title"].toLowerCase().indexOf(statusSent["filter"].toLowerCase()) >= 0) || 
							(val["from"].toLowerCase().indexOf(statusSent["filter"].toLowerCase()) >= 0) || 
							(val["to"].toLowerCase().indexOf(statusSent["filter"].toLowerCase()) >= 0) ||
							(val["fromName"].toLowerCase().indexOf(statusSent["filter"].toLowerCase()) >= 0) ||
							(val["toName"].toLowerCase().indexOf(statusSent["filter"].toLowerCase()) >= 0);
						
				});
			}
			if(selectusers!="")
			{
				Odata["a" + stab] =  $.grep(Odata["a" + stab],function(val,key){
					var a_selectusers = selectusers.split(";");
					var filterto = false;
					$.each(a_selectusers,function(index,v) {
						if (val["to"].toLowerCase().indexOf(v) >=0)
						{
							filterto = true;
							return;
						}
					});
					return (selectusers.toLowerCase().indexOf(val["from"].toLowerCase()) >= 0) || filterto;
				});
			}
		}
		
		statusSent["MailTotal"] = Odata["a" + stab].length;
		statusSent["PageTotal"] = Math.ceil(statusSent["MailTotal"] / 10);		
		if(statusSent["CurPage"] > statusSent["PageTotal"] && statusSent["PageTotal"] > 0)
		{			
			statusSent["CurPage"] = statusSent["PageTotal"];
			statusSent["PageLast"] = 1;
		}
		if(statusSent["tmpPageTotal"] > statusSent["PageTotal"] && 	statusSent["CurPage"] == statusSent["PageTotal"])
		{
			statusSent["PageLast"] = 1;
		}			
	}

}
function searchTXT(stab)
{
	if (stab == "Inbox")
	{	
		if ($("#Inbox_search").val() != "在这里输入搜索条件" && $("#Inbox_search").val() != "")
		{	
			statusInbox["filter"] = $("#Inbox_search").val();
			$("#Inbox_search_btn").attr("imgstates","1");
			$("#Inbox_search_btn").css("background","url(img/mail_search_btn_d.gif) right top no-repeat");				
		}
		else
		{	
			$("#Inbox_search_btn").attr("imgstates","0");		
			statusInbox["filter"] = "";
			$("#Inbox_search").css("color","gray");
		}
	}
	else
	{
		if ($("#Sent_search").val() != "在这里输入搜索条件" && $("#Sent_search").val() != "")
		{	
			
			statusSent["filter"] = $("#Sent_search").val();
			$("#Sent_search_btn").attr("imgstates","1");
			$("#Sent_search_btn").css("background","url(img/mail_search_btn_d.gif) right top no-repeat");
		}
		else
		{
			$("#Sent_search_btn").attr("imgstates","0");
			statusSent["filter"] = "";
			$("#Sent_search").css("color","gray");
		}
	}
	reflashmaillist();
//	goPage(1,stab);
	PageFirst(stab);
}

function OpenMailPOP(seq,stab,el,index)
{
	if ( Odata["a" + stab][index]["unread"] == "1")
	{
		if(	statusInbox["UnreadMailTotal"]>0)
		{
			statusInbox["UnreadMailTotal"]=	statusInbox["UnreadMailTotal"]-1;
		}
		else
		{
			statusInbox["UnreadMailTotal"]=0;
		}
		$("#InboxNum").text(statusInbox["UnreadMailTotal"].toString());//收件箱总邮件数量
		if(stab == "Inbox")
		{	
			MarkRead(seq);//未读
		}
		Odata["a" + stab][index]["unread"] = "0";
		$(el).children("p").children("span").removeAttr("style");		
	}
	if (Odata["a" + stab][index]["type"] == "4" && stab == "Inbox")
	{
		var mkcode = Odata["a" + stab][index]["goldcode"];
		OpenShortMail(seq,mkcode);
	}else if(Odata["a" + stab][index]["producttype"] !="0" && stab == "Inbox"){
		if(Odata["a" + stab][index]["producttype"] =="3"){
			gototrialmail(seq);  //14天产品试用快速开通
		}else if(Odata["a" + stab][index]["producttype"] =="2"){
			gotoenduegoldmail(seq);//短期黄金眼快速开通
		}else{
			gotoproductmail(seq);//产品中心阅读窗口
		}
	}else if(Odata["a" + stab][index]["type"] == "7" && stab == "Inbox"){
		gotoenduegoldmail(seq);  //短期黄金眼快速开通
	}else{
		OpenPOPMail("page=qlmail.htm?seq=" + seq);
	}
}
//打开短期黄金眼快速赋权窗口
function  gotoenduegoldmail(seq)
{
	var url = window.location.href;
	if (url.lastIndexOf("/") >= 0)
	{
		url = url.substring(0,url.lastIndexOf("/web/") + 4);
	}
	url = url.replace(/\//g,"\\");
	url = url + "\\procenter\\enduegoldmail.htm?seqtype=1&seq="+ seq;
	var tmptitle="阅读邮件";
	OpenShowEnduGoldMail(tmptitle,url);
}
//打开14试用快速赋权窗口
function  gototrialmail(seq)
{
	var url = window.location.href;
	if (url.lastIndexOf("/") >= 0)
	{
		url = url.substring(0,url.lastIndexOf("/web/") + 4);
	}
	url = url.replace(/\//g,"\\");
	url = url + "\\procenter\\producttrialmail.htm?seqtype=1&seq="+ seq;
	var tmptitle="阅读邮件";
	OpenShowEnduGoldMail(tmptitle,url);
}

//打开产品中心阅读窗口
function  gotoproductmail(seq)
{
	var url = window.location.href;
	if (url.lastIndexOf("/") >= 0)
	{
		url = url.substring(0,url.lastIndexOf("/web/") + 4);
	}
	url = url.replace(/\//g,"\\");
	url = url + "\\procenter\\popmail.htm?seqtype=1&seq="+ seq;
	var tmptitle="阅读邮件";
	OpenShowEnduGoldMail(tmptitle,url);
}

function testshowwindow_suoqu()
{
	var url = window.location.href;
	if (url.lastIndexOf("/") >= 0)
	{
		url = url.substring(0,url.lastIndexOf("/web/") + 4);
	}
	url = url.replace(/\//g,"\\");
	url = url + "\\procenter\\testopenservicemode1.htm";
	var tmptitle="测试索取";

	/*
*在客户端打开新窗口
*参数：tmptitle：标题  tmpurl:页面地址  a:最大化(1)最小化（2）全部（3）  b:拖动（1）不拖动（0）  c:窗口尺寸（|分隔）  d: 模态（1）非模态（0）  e:窗口ID f:窗口位置（0居中 1左上2右上3左下4右下）
*/
//	data =f_client_call("S_Info_NavUrl",tmpurl);	
	data =f_client_call("S_Info_ShowUrl",tmptitle+"\r\n"+url+"\r\na=0\r\nb=1\r\nc=531|351\r\nd=0\r\ne=1011\r\nf=0");
	data = null;

}
//打开回执列表窗口
function OpenMailReturnList(i)
{
	var tmpseq=Odata["aSent"][i]["seq"];
	var tmptitle=Odata["aSent"][i]["title"];
	client_data_save("qlmaimailtitlekey","1",tmptitle,"0");
	OpenReturnList(".\\mail\\returnlist.htm?mailtitlekey=qlmaimailtitlekey&seq=" + tmpseq +"&customdatakey=" + saveCustomDataKeyName);
}
//返回当前邮件已阅读人数
function GetReturnListNumber(seq)
{
	datainfo=[];
	var data=GetReturnMailState(seq);
	if(data !=undefined && data != "")
	{
		datainfo=data.split("|");
		return datainfo[0];
	}
	return 0;
}
function changeVersion(value)
{
	switch (value)
	{
		case "0":
			$("#ddborker1").show();//经纪人
			$("#ddborker2").show();
			$("#ddmailselect1").hide();//筛邮件
			$("#ddmailselect2").hide();		
			break;
		case "1":
			$("#ddborker1").hide();
			$("#ddborker2").hide();
			$("#ddmailselect1").show();//筛邮件
			$("#ddmailselect2").show();		
			break;
	}
}

function changetab(page)
{
//	$("#inbox").toggleClass("mail_tab_bg");
//	$("#send").toggleClass("mail_tab_bg");
//	$("#inboxdiv").toggle();
//	$("#senddiv").toggle();
	switch	(page)
	{
		case "Inbox":
			if(itab=="Sent")
			{
				$("#inbox").toggleClass("mail_tab_bg","switch");
				$("#inboxdiv").toggle();
				$("#send").toggleClass("mail_tab_bg");
				$("#senddiv").toggle();
				itab = "Inbox";
			}
			break;
		case "Sent":
			if(itab=="Inbox")
			{
				$("#send").toggleClass("mail_tab_bg","switch");
				$("#senddiv").toggle();
				$("#inbox").toggleClass("mail_tab_bg");
				$("#inboxdiv").toggle();
				itab = "Sent";
			}
			break;
		default:
			itab = "Sent";
	}
}

function showbroker()
{
	$("#div_loading").css("top","43");
	$("#maildiv").hide();
	$("#borkerdiv").show();
	$("#footer").show();
	//document.firstChild.nodeValue="DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"";
	$("body").css("padding-bottom","5px");
	$("#brokerlist").css("position","relative");
	showbrokerlist();
	showbrokerlistcontrol();
}

/**  
* 图片出错处理，可以重加载指定的图片。超过重试次数仍不能正常显示的，显示缺省图片。  
* 示例<img onerror="showImgDelay(this,'1.jpg',2)" src="1.jpg">  
*  
* imgObj:img节点对象  
* imgSrc:出错时加载的图片地址  
* maxErrorNum:最大出错次数，防止出现死循环  
*/  
function showImgDelay(imgObj,imgSrc,maxErrorNum){ 
    if(maxErrorNum>0){  
        imgObj.onerror=function(){  
            showImgDelay(imgObj,imgSrc,maxErrorNum-1);  
        };  
        setTimeout(function(){  
            imgObj.src=imgSrc;  
        },500);  
    }else{  
        imgObj.onerror=null;  
        imgObj.src="img/no_person.gif";  
    }  
}  


//显示经纪人列表
function showbrokerlist()
{  	
	var qsid = getSysUser()[2];
	var strBroker = "";
	var tstrBroker = "";
	var brokers = load_BrokerData("1");
	var m=0,n=0;
	if(brokers.length > 0)
	{		
		strBroker +="<div class=\"list_title\">我的客户经理</div>";
		tstrBroker +="<div class=\"list_title\">我的投资顾问</div>";
		for (var i=0; i < brokers.length; i++)
		{	//收起展开	
			var bimg = "img/people.gif";
			if(brokers[i].ol==1) {
				bimg = "img/mail_btn03.gif";
			}
			var img = brokers[i].img;		
			if(img==null || img=="") {
				img = "img/no_person.gif";
			} 
			else
			{
				if (img.toLowerCase().indexOf("http://") == 0)
				{
					img = img.substring(7);
					img = img.substring(img.indexOf("/") + 1);
				};
				img = G_ATTACHPATH() + img;
			}
			if(brokers[i].role==2) {
				if(m%2==0) {
					
					strBroker +=" <div class=\"mail_business_card\" title=\"点击发信\" onclick=\"javascript:sendbrokermail('"+ brokers[i].nm + "');return false;\" >";
				} else {
					strBroker +=" <div class=\"mail_business_card\" title=\"点击发信\" style=\"background:#e7f3fe;\" onclick=\"javascript:sendbrokermail('"+ brokers[i].nm + "');return false;\" >";
				}	

				strBroker +="   <dl>";
				strBroker +="	  <dd><b style='background:url("+bimg+") no-repeat;' >"+brokers[i].nm+
				"</b><h1 onmouseover=\"changecolors(this,'over');\" onmouseout=\"changecolors(this,'out');\" onclick=\"window.event.cancelBubble = true; changeBroker('"+brokers[i].id+"','"+qsid+"');\" title=\"进入主页\"></h1></dd>";
				//strBroker +="	  <dd><span><em>"+ brokers[i].mobile +"</em></span></dd>";
				strBroker +="	  <dd title=\""+brokers[i].cerid+"\"><font>执照</font><em>"+brokers[i].cerid+"</em></dd>";
				strBroker +="   </dl>"; 
				strBroker +="   <dl class=\"mail_business_card_open\">";
				strBroker +="     <dt><img src=\""+img+"\" onerror='showImgDelay(this,this.src,2);' /></dt>";
				strBroker +="	  <dd title=\""+brokers[i].mobile+"\"><font>手机</font><em>"+brokers[i].mobile+"</em></dd>";
				strBroker +="	  <dd><font>性别</font><em>"+brokers[i].gender+"</em></dd>";
				strBroker +="	  <dd><font>学历</font><em>"+brokers[i].edu+"</em></dd>";	
				strBroker +="	  <dd title=\""+brokers[i].pos+" \"><font>职位</font><em>"+brokers[i].pos+"</em></dd>";	
				strBroker +="	  <dd title=\""+brokers[i].exyears+"年 \"><font>经验</font><em>"+brokers[i].exyears+"年</em></dd>";
				//strBroker +="	  <dd title=\""+brokers[i].qq+" \"><font>QQ</font><em>"+brokers[i].qq+"</em></dd>";
				strBroker +="	  <dd title=\""+brokers[i].phone+" \"><font>固话</font><em>"+brokers[i].phone+"</em></dd>";		
				strBroker +="   </dl>";
				strBroker +=" </div>"; 

				strBroker +=" <div class=\"clear\"></div>";
				m++
			} else if(brokers[i].role==1) {
				if(n%2==0) { 
					
					tstrBroker +=" <div class=\"mail_business_card\" title=\"点击发信\" onclick=\"javascript:sendbrokermail('"+ brokers[i].nm + "');return false;\" >";
				}
				else {
					tstrBroker +=" <div class=\"mail_business_card\" title=\"点击发信\" style=\"background:#e7f3fe;\" onclick=\"javascript:sendbrokermail('"+ brokers[i].nm + "');return false;\">";
				}	
				tstrBroker +="   <dl title=\"点击发信\">";
				tstrBroker +="	  <dd><b style='background:url("+bimg+") no-repeat;'>"+brokers[i].nm+
				"</b><h1 onmouseover=\"changecolors(this,'over');\" onmouseout=\"changecolors(this,'out');\" onclick=\"window.event.cancelBubble = true; changeBroker('"+brokers[i].id+"', '"+qsid+"');\" title=\"进入主页\"></h1></dd>";
				//tstrBroker +="	  <dd><span><em>"+ brokers[i].mobile +"</em></span></dd>";
				tstrBroker +="	  <dd title=\""+brokers[i].cerid+"\"><font>执照</font><em>"+brokers[i].cerid+"</em></dd>";
				tstrBroker +="   </dl>"; 
				tstrBroker +="   <dl class=\"mail_business_card_open\">";

				tstrBroker +="     <dt><img src=\""+img+"\" onerror='showImgDelay(this,this.src,2);' /></dt>";
				tstrBroker +="	  <dd title=\""+brokers[i].mobile+"\"><font>手机</font><em>"+brokers[i].mobile+"</em></dd>";
				tstrBroker +="	  <dd><font>性别</font><em>"+brokers[i].gender+"</em></dd>";
				tstrBroker +="	  <dd><font>学历</font><em>"+brokers[i].edu+"</em></dd>";	
				tstrBroker +="	  <dd title=\""+brokers[i].pos+"\"><font>职位</font><em>"+brokers[i].pos+"</em></dd>";	
				tstrBroker +="	  <dd title=\""+brokers[i].exyears+"年 \"><font>经验</font><em>"+brokers[i].exyears+"年</em></dd>";
				//tstrBroker +="	  <dd title=\""+brokers[i].qq+" \"><font>QQ</font><em>"+brokers[i].qq+"</em></dd>";
				tstrBroker +="	  <dd title=\""+brokers[i].phone+" \"><font>固话</font><em>"+brokers[i].phone+"</em></dd>";		
				tstrBroker +="   </dl>";
				tstrBroker +=" </div>"; 

				tstrBroker +=" <div class=\"clear\"></div>";
				n++;
			}
		}
		
	}
	if(strBroker=="") {
		strBroker =" <h1><span style=\" font-size: 15px; algin:center; padding-left:10px;\"><font color=\"#808080\">当前列表无经纪人信息</font></span></h1>";
	
	}
	if(m>0) {
		$("#brokerlist").html(strBroker); 
	}
	if(n>0) {
		if(m==0) {
			$("#brokerlist").html(tstrBroker); 
		} else {
			$("#brokerlist").append(tstrBroker); 
		} 
	}
}

function changeBroker(bid, qsid){
	var url = G_TGPATH() + "qs/initMain.do";
	url += "?qsid="+qsid+"&bid=" + bid ;
	openMain(url);
}

function changecolors(obj,st) {
	if(st=="over") {
	//$(".mail_business_card h1").hover(function(i) {
			$(obj).css("background", "url(img/icon_house_down.gif) right top no-repeat");
	//	});
	} else {
	//	$(".mail_business_card h1").hover(function(i) {
			$(obj).css("background", "url(img/icon_house_up.gif) right top no-repeat");
	//	});
	}
}

//控制经纪人列表显示和隐藏
function showbrokerlistcontrol()
{
	$(".mail_business_card").each(function(i,div) {
		//if(i == 0) {
			//$(this).find("img:eq(0)").attr("src","img/ss_mail_icon4.gif");
			$(div).find(".mail_business_card_open").show();
			//$(div).height(191);
		//}
		/*$(div).find("img:eq(0)").click(function(){
			if($(this).attr("src").indexOf("icon3")> 0)
			{					
				$(this).attr("src","img/ss_mail_icon4.gif");
				$(div).children(".mail_business_card_open").show();
				//$(div).height(191);
			}
			else
			{
				$(this).attr("src","img/ss_mail_icon3.gif");
				$(div).children(".mail_business_card_open").hide();
				//$(div).height(52);
			}
			
		});*/
	});
}
//给当前经纪人发送信息
function sendbrokermail(value)
{
	switch (version)
	{
		case "0":
			OpenMailCenter('page=writemail.htm&pre=qlmail.htm&um='+value);							
			break;
		case "1":		
			break;
	}
}
/*
function brokerlistcs(obj)
{
	$(obj).css("background","#e4f5ff");
}
function brokerlistch(obj)
{
	$(obj).css("background","");
}
*/
function showmail()
{
	showLoading();	
//筛邮件隐藏
	$("#content").hide();
	$("#contentBtn").hide();
	$("html").css("overflow-y","scroll");
	$(".wrapper").show();	
//筛邮件结束
	if(($("#Inbox_search").val() != "在这里输入搜索条件" && $("#Inbox_search").val() != "") || ($("#Sent_search").val() != "在这里输入搜索条件" && $("#Sent_search").val() != "")||statusInbox["filter"] != "" ||statusSent["filter"] != "")
	{	
		$("#Inbox_search").val("在这里输入搜索条件");
		$("#Sent_search").val("在这里输入搜索条件");
		$("#Inbox_search").css("color","gray");
		$("#Sent_search").css("color","gray");
		statusInbox["filter"] = "";
		statusSent["filter"] = "";
		reflashmaillist();		
	}	
	PageFirst("Inbox");
	PageFirst("Sent");
//	goPage(1,"Inbox");
//	goPage(1,"Sent");
	$("#maildiv").show();
	$("#borkerdiv").hide();
	$("#footer").hide();
	//document.firstChild.nodeValue="DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"";
	//$("body").css("padding-bottom","0");
	ReceiveMail();
}

function reflashmaillist()
{
	Odata = getMailLists();
	var tmppage =1;
//	$("#InboxNum").text(Odata["iInbox"].toString());
	ListMail("Inbox");
	ListMail("Sent");
	if (statusSent["PageTotal"] > 3)
	{
		 tmppage=statusSent["CurPage"];	
		if(tmppage<1)
		{
			tmppage=1;
		}
		if(tmppage == 1)
		{
			$("#Sent_foot").show();
			$("#li_Sent_first").show();
			$("#li_Sent_1").show();
			$("#li_Sent_1").attr("pageIndex",1);
			$("#li_Sent_1").attr("tab","Sent");
			$("#li_Sent_1 a").text("1");
			$("#li_Sent_2").show();
			$("#li_Sent_2").attr("pageIndex",2);
			$("#li_Sent_2").attr("tab","Sent");
			$("#li_Sent_2 a").text("2");
			$("#li_Sent_3").show();
			$("#li_Sent_3").attr("pageIndex",3);
			$("#li_Sent_3").attr("tab","Sent");
			$("#li_Sent_3 a").text("3");
			$("#li_Sent_last").show();
		}
		else if(tmppage == statusSent["PageTotal"])
		{
			$("#Sent_foot").show();
			$("#li_Sent_first").show();
			$("#li_Sent_1").show();
			$("#li_Sent_1").attr("pageIndex",(tmppage-2).toString());
			$("#li_Sent_1").attr("tab","Sent");
			$("#li_Sent_1 a").text((tmppage-2).toString());
			$("#li_Sent_2").show();
			$("#li_Sent_2").attr("pageIndex",(tmppage-1).toString());
			$("#li_Sent_2").attr("tab","Sent");
			$("#li_Sent_2 a").text((tmppage-1).toString());
			$("#li_Sent_3").show();
			$("#li_Sent_3").attr("pageIndex",tmppage.toString());
			$("#li_Sent_3").attr("tab","Sent");
			$("#li_Sent_3 a").text(tmppage.toString());
			$("#li_Sent_last").show();
		
		}
		else
		{
			$("#Sent_foot").show();
			$("#li_Sent_first").show();
			$("#li_Sent_1").show();
			$("#li_Sent_1").attr("pageIndex",(tmppage-1).toString());
			$("#li_Sent_1").attr("tab","Sent");
			$("#li_Sent_1 a").text((tmppage-1).toString());
			$("#li_Sent_2").show();
			$("#li_Sent_2").attr("pageIndex",tmppage.toString());
			$("#li_Sent_2").attr("tab","Sent");
			$("#li_Sent_2 a").text(tmppage.toString());
			$("#li_Sent_3").show();
			$("#li_Sent_3").attr("pageIndex",(tmppage+1).toString());
			$("#li_Sent_3").attr("tab","Sent");
			$("#li_Sent_3 a").text((tmppage+1).toString());
			$("#li_Sent_last").show();
		}
	}
	else if (statusSent["PageTotal"] == 3)
	{
		$("#Sent_foot").show();
		$("#li_Sent_first").hide();
		$("#li_Sent_1").show();
		$("#li_Sent_1").attr("pageIndex",1);
		$("#li_Sent_1").attr("tab","Sent");
		$("#li_Sent_1 a").text("1");
		$("#li_Sent_2").show();
		$("#li_Sent_2").attr("pageIndex",2);
		$("#li_Sent_2").attr("tab","Sent");
		$("#li_Sent_2 a").text("2");
		$("#li_Sent_3").show();
		$("#li_Sent_3").attr("pageIndex",3);
		$("#li_Sent_3").attr("tab","Sent");
		$("#li_Sent_3 a").text("3");
		$("#li_Sent_last").hide();
	}
	else if (statusSent["PageTotal"] == 2)
	{
		$("#Sent_foot").show();
		$("#li_Sent_first").hide();
		$("#li_Sent_1").show();
		$("#li_Sent_1").attr("pageIndex",1);
		$("#li_Sent_1").attr("tab","Sent");
		$("#li_Sent_1 a").text("1");
		$("#li_Sent_2").show();
		$("#li_Sent_2").attr("pageIndex",2);
		$("#li_Sent_2").attr("tab","Sent");
		$("#li_Sent_2 a").text("2");
		$("#li_Sent_3").hide();
		$("#li_Sent_last").hide();
	}
	else if (statusSent["PageTotal"] == 1)
	{
		$("#Sent_foot").show();
		$("#li_Sent_first").hide();
		$("#li_Sent_1").show();
		$("#li_Sent_1").attr("pageIndex",1);
		$("#li_Sent_1").attr("tab","Sent");
		$("#li_Sent_1 a").text("1");
		$("#li_Sent_2").hide();
		$("#li_Sent_3").hide();
		$("#li_Sent_last").hide();
	}
	else
	{
		$("#Sent_foot").hide();
	}

	if (statusInbox["PageTotal"] > 3)
	{
		 tmppage=statusInbox["CurPage"];	
		 if(tmppage<1)
		 {		 
			 tmppage=1;
		 }
		if(tmppage == 1)
		{
			$("#Inbox_foot").show();
			$("#li_Inbox_first").show();
			$("#li_Inbox_1").show();
			$("#li_Inbox_1").attr("pageIndex","1");
			$("#li_Inbox_1").attr("tab","Inbox");
			$("#li_Inbox_1 a").text("1");
			$("#li_Inbox_2").show();
			$("#li_Inbox_2").attr("pageIndex","2");
			$("#li_Inbox_2").attr("tab","Inbox");
			$("#li_Inbox_2 a").text("2");
			$("#li_Inbox_3").show();
			$("#li_Inbox_3").attr("pageIndex","3");
			$("#li_Inbox_3").attr("tab","Inbox");
			$("#li_Inbox_3 a").text("3");
			$("#li_Inbox_last").show();
		}
		else if(tmppage == statusInbox["PageTotal"])
		{
			$("#Inbox_foot").show();
			$("#li_Inbox_first").show();
			$("#li_Inbox_1").show();
			$("#li_Inbox_1").attr("pageIndex",(tmppage-2).toString());
			$("#li_Inbox_1").attr("tab","Inbox");
			$("#li_Inbox_1 a").text((tmppage-2).toString());
			$("#li_Inbox_2").show();
			$("#li_Inbox_2").attr("pageIndex",(tmppage-1).toString());
			$("#li_Inbox_2").attr("tab","Inbox");
			$("#li_Inbox_2 a").text((tmppage-1).toString());
			$("#li_Inbox_3").show();
			$("#li_Inbox_3").attr("pageIndex",tmppage.toString());
			$("#li_Inbox_3").attr("tab","Inbox");
			$("#li_Inbox_3 a").text(tmppage.toString());
			$("#li_Inbox_last").show();
		}
		else
		{
			$("#Sent_foot").show();
			$("#li_Inbox_first").show();
			$("#li_Inbox_1").show();
			$("#li_Inbox_1").attr("pageIndex",(tmppage-1).toString());
			$("#li_Inbox_1").attr("tab","Inbox");
			$("#li_Inbox_1 a").text((tmppage-1).toString());
			$("#li_Inbox_2").show();
			$("#li_Inbox_2").attr("pageIndex",tmppage.toString());
			$("#li_Inbox_2").attr("tab","Inbox");
			$("#li_Inbox_2 a").text(tmppage.toString());
			$("#li_Inbox_3").show();
			$("#li_Inbox_3").attr("pageIndex",(tmppage+1).toString());
			$("#li_Inbox_3").attr("tab","Inbox");
			$("#li_Inbox_3 a").text((tmppage+1).toString());
			$("#li_Inbox_last").show();		
		}		
	
	}
	else if (statusInbox["PageTotal"] == 3)
	{
		$("#Inbox_foot").show();
		$("#li_Inbox_first").hide();
		$("#li_Inbox_1").show();
		$("#li_Inbox_1").attr("pageIndex","1");
		$("#li_Inbox_1").attr("tab","Inbox");
		$("#li_Inbox_1 a").text("1");
		$("#li_Inbox_2").show();
		$("#li_Inbox_2").attr("pageIndex","2");
		$("#li_Inbox_2").attr("tab","Inbox");
		$("#li_Inbox_2 a").text("2");
		$("#li_Inbox_3").show();
		$("#li_Inbox_3").attr("pageIndex","3");
		$("#li_Inbox_3").attr("tab","Inbox");
		$("#li_Inbox_3 a").text("3");
		$("#li_Inbox_last").hide();
	}
	else if (statusInbox["PageTotal"] == 2)
	{
		$("#Inbox_foot").show();
		$("#li_Inbox_first").hide();
		$("#li_Inbox_1").show();
		$("#li_Inbox_1").attr("pageIndex","1");
		$("#li_Inbox_1").attr("tab","Inbox");
		$("#li_Inbox_1 a").text("1");
		$("#li_Inbox_2").show();
		$("#li_Inbox_2").attr("pageIndex","2");
		$("#li_Inbox_2").attr("tab","Inbox");
		$("#li_Inbox_2 a").text("2");
		$("#li_Inbox_3").hide();
		$("#li_Inbox_last").hide();
	}
	else if (statusInbox["PageTotal"] == 1)
	{
		$("#Inbox_foot").show();
		$("#li_Inbox_first").hide();
		$("#li_Inbox_1").show();
		$("#li_Inbox_1").attr("pageIndex","1");
		$("#li_Inbox_1").attr("tab","Inbox");
		$("#li_Inbox_1 a").text("1");
		$("#li_Inbox_2").hide();
		$("#li_Inbox_3").hide();
		$("#li_Inbox_last").hide();
	}
	else
	{
		$("#Inbox_foot").hide();
	}
}

function showwritemail()
{
	switch (version)
	{
		case "0":
			OpenMailCenter('page=writemail.htm');
			break;
		case "1":
			var today = new Date();
			var times = today.getMinutes() * 60 * 1000 + today.getSeconds() * 1000 + today.getMilliseconds();
			OpenMailCenter('page=businesscard.htm&t=' + times.toString());
			break;
	}
}
//隐藏进度
function hidLoading()
{
	G_Parent.GLOBAL_Loading="False";
	$("#div_loading").hide();
}
//显示进度条
function showLoading()
{
	$("#div_loading").show();
	G_Parent.GLOBAL_Loading="True";
}
//判断时间--昨天
function getDateDiff(varparam)
{ 
	try
	{
		var result="";
		var tmpRea = ql_date_yyyymmdd(varparam);//邮件时间（YYYYMMDD）
		var tmpTad = ql_date_yyyymmdd(GetDateStr(0));//今天天（YYYYMMDD）
		var tmpYes = ql_date_yyyymmdd(GetDateStr(-1));//昨天（YYYYMMDD）
		if(tmpRea==tmpTad)
		{			
			result=varparam.substring(11,varparam.length);			
		}
	 	else if(tmpRea == tmpYes)
		{
			result = "昨天";
		}
		else
		{
			result= tmpRea;
		}
	}
	catch(e)
	{
		result="";
	}
	return result;	
}
//计算日期为昨天函数
 function GetDateStr(AddDayCount) {  
     var dd = new Date();  
     dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期  
     var y = dd.getFullYear();  
     var m = dd.getMonth()+1;//获取当前月份的日期  
     var d = dd.getDate();  
     return y+"-"+m+"-"+d;  
 }  
 
function myload(){
	initattachsetting();//注册上传附件大小及服务器地址
	checkversions();//判断服务器版本，如发生变更，删除缓存

	recordtime("必要的JS文件加载完成");
	recordstart(0);
	var investorheight = $(window).height() - 60;
	$(".investor_body").height(investorheight);
	version = GetVersion();
	changeVersion(version);
	load_Base();
	recordtime("获取平台数据完成(远程/本地缓存)完成");
	ReceiveMail();
	reflashmaillist();
	goPage(1,"Inbox");
	goPage(1,"Sent");
	$("#Inbox_search").val("在这里输入搜索条件");
	$("#Inbox_search").css("color","gray");
	$("#Sent_search").val("在这里输入搜索条件");
	$("#Sent_search").css("color","gray");
//	$("#Inbox_search,#Sent_search").focus(function(){	
//		$(".mail_search_btn").css("background","url(img/mail_search_btn_down.gif) right top no-repeat");
//	});
	$("#Inbox_search,#Sent_search").blur(function(){
		if($("#Inbox_search").val() != "在这里输入搜索条件" && $("#Inbox_search").val() != ""&& $("#Inbox_search_btn").attr("imgstates")=="1")
		{
			$("#Inbox_search_btn").css("background","url(img/mail_search_btn_d.gif) right top no-repeat");
		}
		else if($("#Inbox_search").val() == "在这里输入搜索条件" && $("#Inbox_search_btn").attr("imgstates")=="1")
		{	
			searchClick("Inbox");	
		}
		else
		{
			$("#Inbox_search_btn").css("background","url(img/mail_search_btn_up.gif) right top no-repeat");
		}
		
		
		if($("#Sent_search").val() != "在这里输入搜索条件" && $("#Sent_search").val() != ""&& $("#Sent_search_btn").attr("imgstates")=="1")
		{
			$("#Sent_search_btn").css("background","url(img/mail_search_btn_d.gif) right top no-repeat");
		}
		else if($("#Sent_search").val() == "在这里输入搜索条件" && $("#Sent_search_btn").attr("imgstates")=="1")
		{
			searchClick("Sent");	
		}
		else
		{
			$("#Sent_search_btn").css("background","url(img/mail_search_btn_up.gif) right top no-repeat");
		}	
	});
	setTimeout('SaveCustomerData()',1000); //延时保存客户信息到本地缓存，数据源在智能键盘内获取

	//本地标签同步服务器
	if(version=="1")//投顾端
	{
		var tmpurls=G_TGPATH() + "/component/labelSyn.jsp";		
		$("#savelable").attr("src",tmpurls);
	}
}
//侧边栏缓存
function SaveCustomerData(){
	var version = GetVersion();
	var customerData;
	switch (version)
	{
		case "0":		
			break;
		case "1":		
			var tmpCustomerData= load_CustomerData("2","","");
			customerData=JSON.stringify(tmpCustomerData);					
			client_data_save(saveCustomDataKeyName,"1",customerData,"0");		
			break;
	}	
}
function searchClick(value)
{
	switch(value)
	{
		case "Inbox":
			if($("#Inbox_search_btn").attr("imgstates")=="1")
			{
				$("#Inbox_search_btn").attr("imgstates","0");
				$("#Inbox_search").val("在这里输入搜索条件");
				$("#Inbox_search_btn").css("background","url(img/mail_search_btn_up.gif) right top no-repeat");
			}	
			break;
		case "Sent":
			if($("#Sent_search_btn").attr("imgstates")=="1")
			{	
				$("#Sent_search_btn").attr("imgstates","0");
				$("#Sent_search").val("在这里输入搜索条件");
				$("#Sent_search_btn").css("background","url(img/mail_search_btn_up.gif) right top no-repeat");
			}
			break;
	}
	searchTXT(value);	
}
/*
*新邮件阅读刷新右侧侧边栏邮件状态
*/
function ChangeNewMailStates(seq){
	var text = GetMail(seq);
	var iFirstContent = text.indexOf("<content><![CDATA[");
	var iLastContent = text.lastIndexOf("]]></content>");
	if ((iFirstContent < 0 ) || (iLastContent < 0))
	{
		return;
	}
	var sbody = 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 sattr = "000000" + parseFloat($($(xml).find("mail")[0]).attr("attrib")).toString(16);
	sattr = sattr.substring(sattr.length-6,sattr.length);
	sattr = parseFloat(sattr.substring(1,2)).toString(2);
	if (sattr.substring(sattr.length -2,sattr.length -1) != "1")
	{
		SetAttrib(seq + "\r\n65536");
		//更新页面邮件状态（未读人数及刷新页面）
		if(	statusInbox["UnreadMailTotal"]>0)
		{
			statusInbox["UnreadMailTotal"]=	statusInbox["UnreadMailTotal"]-1;
		}
		else
		{
			statusInbox["UnreadMailTotal"]=0;
		}
		try{
			var tmpIndex=G_MailList_hash_index[seq];		
			Odata["aInbox"][tmpIndex]["unread"] = "0";
			$("#InboxNum").text(statusInbox["UnreadMailTotal"].toString());//收件箱总邮件数量
			$("#li_"+seq).children("p").children("span").removeAttr("style");		
		}catch(e){			
		}
	}
	else
	{
		SetAttrib(seq + "\r\n196608");
	}
	var srvseq = $($(xml).find("mail")[0]).attr("srvseq");
	if(srvseq==undefined)
	{
		srvseq="";
	}
	var sfrom = $($(xml).find("from")[0]).text();
	var tmpparam=srvseq+"|"+sfrom+"|0";
	WriteReceipt(tmpparam);//回执
}
