var Oparamter = "";
var NewEmailSeq = "";
var sourceSeq = "";
var sourcesrvSeq = "";
var sourceType = "";
var sourceFrom="";
var brokersData;
var sendprocess;
var sendMailTimeState="false";//发送邮件计时是否启用
var g_content = ""; //回复的文本内容
var default_content="";//文本默认值
var g_sendlogtype = "";
var g_sendlogtxt = "";
var g_senders = [];
var g_gid = "";
var NeedLoadbrokers = true;//判断列表是否加载成功
var cachebrokers = null;
var cacheindex = 0;
var total_imgsize = 0;
//mailjs();
function operatemail(values)
{
	clearMail();
	Oparamter = values;
	value = getparamter(values,"page");
	switch (value)
	{
	case "maillist.htm":
		window.location = "maillist.htm?" + values;
		break;
	case "businesscard.htm":
		window.location = "businesscard.htm?" + values;
		break;
	}
	var seq = getparamter(values,"seq");
	var pre = getparamter(values,"pre");
	var um = getparamter(values,"um");
	if(seq != "" && pre=="popmail.htm")
	{
		ReadMail(seq);
		ifrmwrEditor.setContent(g_content);//设置富文本为默认值
	}
	else
	{
		ifrmwrEditor.setContent("");//设置富文本为默认值
	}
	if(pre=="qlmail.htm" && um!="")
	{
		$("#txtSender").text(um);
		chkBrokers(um);	
		ListEndchkbrokers();//判断右侧勾选
	}
}

//利用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();
	sourcesrvSeq = $($(xml).find("mail")[0]).attr("srvseq");
	sourceFrom = sfrom;
	brokersData = load_BrokerData("2");
	if(brokersData.length > 0)
	{	
		for (var i=0; i < brokersData.length; i++)
		{				
			var id = (brokersData[i].id).toLowerCase();
			if(id == sfrom)
			{
				sfrom = brokersData[i].nm;			
				break ;
			}
		}
	}
	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());
	$("#txtSender").text(sfrom);
	$("#txtTitle").val("回复:"+stitle);
//	sTmp = "<br><br><div class='font_gray'>---------------------------------------------------<br>";
//	sTmp +="发件人: "+sfrom+"<br>";
//	sTmp +="发送时间: "+stimestamp+"<br>";
//	sTmp +="收件人: "+sto+"<br>";
//	sTmp +="主题: "+html_encode(stitle)+"<br>";
//	var strindex = sbody.indexOf("友情提示"); 
//	if (strindex != -1)//过滤掉重新登录按钮
//	{
//		sbody=sbody.substring(0,strindex) +"</div>";
//	}
//	sbody = checkattachstrip(sbody);//过滤附件内容
//	sbody = checkimgstrip(sbody);
//	sbody = checkoldimgstrip(sbody);
//	sbody = sTmp + sbody + "</div>";
	g_content = "";
	chkBrokers(sfrom);
}
/*
*利用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 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 chkBrokers(um)
{	
	$("#brokerlist div").each(function()
	{		
		var chk = $(this).children("ul:eq(0)").find("input");
		if( $(chk).attr("username")==um)
		{
			$(chk).attr("checked",true);
			return;
		}				
	})
}
//延时加载完成后判断右侧重新判断勾选
function ListEndchkbrokers()
{
	var txtsenderid = "#txtSender";	
	var sendername = $.trim($(txtsenderid).text()).split(";");
	if(sendername.length>0)
	{
		for (var i=0; i < sendername.length; i++)
		{
			var um = (sendername[i]).toLowerCase();
			
			$("#brokerlist").find("input[class='cl_broker']").each(function()
			{		
				if( $(this).attr("username")==um)
				{
					this.checked = true;
					
					return;
				}
			});
			$("#brokerlist").find("input[class='cl_tbroker']").each(function()
			{	
				if( $(this).attr("username")==um)
				{
					this.checked = true;
					return;
				}
			});
		}
	}
}

function changeTab(tabid)
{
	var i;
	for(i=0; i < 4; i++)
	{
		if(i == tabid)
			$("#content"+i).show();
		else
			$("#content"+i).hide();
	}
}

//延时加载经纪人列表
function DelayLoadbrokers()
{
	var strBrokers = [];
	for (var i=0; i < 5 ; i++)
	{	
		if (typeof(cachebrokers[cacheindex]) == "undefined") break;
		strBrokers.push("<div class=\"mail_broker_item\">");
		strBrokers.push("<ul><li><label class=\"fl\"><input type=\"checkbox\"  username=\"");
		strBrokers.push(cachebrokers[cacheindex].nm);
		strBrokers.push("\"  onclick=\"javascript:chgSender(this);\"></input></label><b title=\"");
		strBrokers.push(cachebrokers[cacheindex].nm);
		strBrokers.push("\">");
		strBrokers.push(cachebrokers[cacheindex].nm);
		strBrokers.push("</b><span>");
		strBrokers.push(cachebrokers[cacheindex].mobile);
		strBrokers.push("</span></li><li><img src=\"img/ss_mail_icon3.gif\" /><font>性别：</font>");
		strBrokers.push(cachebrokers[cacheindex].gender);
		strBrokers.push("</li></ul><ul class=\"mail_broker_item_open\"><li><font>固定电话：</font>");
		strBrokers.push(cachebrokers[cacheindex].phone);
		strBrokers.push("</li><li><font>QQ：</font>");
		strBrokers.push(cachebrokers[cacheindex].qq);
		strBrokers.push("</li>");
		var tmpmsn="";
		if(cachebrokers[cacheindex].msn.length >13)
		{
			tmpmsn=cachebrokers[cacheindex].msn.substring(0,13)+"…";
		}
		else
		{
			tmpmsn=cachebrokers[cacheindex].msn;
		}
		strBrokers.push("<li title=\"");
		strBrokers.push(cachebrokers[cacheindex].msn);
		strBrokers.push(" \"><font>MSN：</font>");
		strBrokers.push(tmpmsn);
		strBrokers.push("</li>");
		var tmpqsNm="";
		if(cachebrokers[cacheindex].qs.length>8)
		{
			tmpqsNm=cachebrokers[cacheindex].qs.substring(0,8)+"…";
		}
		else
		{
			tmpqsNm=cachebrokers[cacheindex].qs;
		}
		strBrokers.push("<li title=\"");
		strBrokers.push(cachebrokers[cacheindex].qs);
		strBrokers.push(" \"><font>所属券商：</font>");
		strBrokers.push(tmpqsNm);
		strBrokers.push("</li><li><font>职位：</font>");
		strBrokers.push(cachebrokers[cacheindex].pos);
		strBrokers.push("</li><li><font>营业部地址：</font>");
		strBrokers.push(cachebrokers[cacheindex].qsAddr);
		strBrokers.push("</li></ul></div>");
		cacheindex++;
		if (cacheindex >= cachebrokers.length) break;
	}	
	$("#brokerlist").append($(strBrokers.join("")));
	if (cacheindex < cachebrokers.length) {
		NeedLoadbrokers = true;
		setTimeout("DelayLoadbrokers()", 5);
	}
	else
	{
		NeedLoadbrokers = false;
		$("#txtCheckAll").attr("style","");
		showbrokerlistcontrol();//设置经纪人显示和隐藏
		ListEndchkbrokers();//判断右侧勾选
	}
}


/**  
* 图片出错处理，可以重加载指定的图片。超过重试次数仍不能正常显示的，显示缺省图片。  
* 示例<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 strBrokers = [];
	var tstrBrokers = [];
	var istrue =true;
	brokersData = load_BrokerData("1");
	if(brokersData.length > 0)
	{	
		cachebrokers = brokersData;
		strBrokers.push("<div class=\"mail_broker_top broker_top_add\">");
		strBrokers.push("	<span><label><input id=\"txtCheckAll\" type=\"checkbox\"  onclick=\"javascript:allsender(this, 'cl_broker');\"/></label></span>");
		strBrokers.push("</div>");
		tstrBrokers.push("<div class=\"mail_broker_top\">");
		tstrBrokers.push("	<span><label><input id=\"ttxtCheckAll\" type=\"checkbox\"  onclick=\"javascript:allsender(this, 'cl_tbroker');\"/></label></span>");
		tstrBrokers.push("</div>");
		var m=0,n=0;
		for (var i=0; i < brokersData.length; i++)
		{	
			var img = cachebrokers[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;
			}
			var bimg = "img/people.gif";
			if(brokersData[i].ol==1) {
				bimg = "img/mail_btn03.gif";
			}
			istrue = false;		
			if(cachebrokers[i].role==2) {
				strBrokers.push("<div class=\"mail_broker_item\" onclick=\"chgDivSender(this, 'cl_broker')\">");
				strBrokers.push("<dl>");
				strBrokers.push("<dd><label class=\"fl\"><input class=\"cl_broker\" type=\"checkbox\"  onclick=\"window.event.cancelBubble = true;chgSender(this)\" username=\"");
				strBrokers.push(cachebrokers[i].nm);
				strBrokers.push("\"></input></label><b style='background:url("+bimg+") no-repeat;' title=\"");
				strBrokers.push(cachebrokers[i].nm);
				strBrokers.push("\">");
				strBrokers.push(cachebrokers[i].nm);
				strBrokers.push("</b><h1 onmouseover=\"changecolor(this,'over');\" onmouseout=\"changecolor(this,'out');\" onclick=\"window.event.cancelBubble = true; changeBroker('"+cachebrokers[i].id+"', '"+qsid+"');\" title=\"进入主页\"></h1></dd>");
				//strBrokers.push(cachebrokers[i].mobile);
				strBrokers.push("<dd title=\""+cachebrokers[i].cerid+"\"><font>执照</font><em>");
				strBrokers.push(cachebrokers[i].cerid);
				strBrokers.push("</em></span></dd>");			
				strBrokers.push("</dl>");
				
				strBrokers.push("<dl class=\"mail_broker_item_open\">");

				strBrokers.push("<dt><img src=\""+img+"\" onerror='showImgDelay(this,this.src,2);' /></dt>");
				strBrokers.push("<dd><font>手机</font><em>");
				strBrokers.push(cachebrokers[i].mobile);
				strBrokers.push("</em><dd><font>性别</font><em>");
				strBrokers.push(cachebrokers[i].gender);
				strBrokers.push("</em></dd><dd><font>学历</font><em>");
				strBrokers.push(cachebrokers[i].edu);
				strBrokers.push("</em></dd><dd title=\""+cachebrokers[i].pos+" \"><font>职位</font><em>");
				strBrokers.push(cachebrokers[i].pos);
				strBrokers.push("</em></dd><dd title=\""+cachebrokers[i].exyears+"年 \"><font>经验</font><em>");
				strBrokers.push(cachebrokers[i].exyears+"年");		
				//strBrokers.push("</em></dd><dd title=\""+cachebrokers[i].qq+" \"><font>QQ：</font><em>");
				//strBrokers.push(cachebrokers[i].qq);			
				strBrokers.push("</em></dd><dd title=\""+cachebrokers[i].phone+" \"><font>固话</font><em>");
				strBrokers.push(cachebrokers[i].phone);			
				strBrokers.push("</em></dd></dl></div>");
				m++;
			} else if(cachebrokers[i].role==1) {
				tstrBrokers.push("<div class=\"mail_broker_item\" onclick=\"chgDivSender(this, 'cl_tbroker')\">");
				tstrBrokers.push("<dl>");
				tstrBrokers.push("<dd><label class=\"fl\"><input class=\"cl_tbroker\" type=\"checkbox\"  onclick=\"window.event.cancelBubble = true;chgSender(this)\" username=\"");
				tstrBrokers.push(cachebrokers[i].nm);
				tstrBrokers.push("\" ></input></label><b style='background:url("+bimg+") no-repeat;' title=\"");
				tstrBrokers.push(cachebrokers[i].nm);
				tstrBrokers.push("\">");
				tstrBrokers.push(cachebrokers[i].nm);
				tstrBrokers.push("</b><h1 onmouseover=\"changecolor(this,'over');\" onmouseout=\"changecolor(this,'out');\" onclick=\"window.event.cancelBubble = true; changeBroker('"+cachebrokers[i].id+"', '"+qsid+"');\" title=\"进入主页\"></h1></dd>");
				//tstrBrokers.push(cachebrokers[i].mobile);
				tstrBrokers.push("<dd title=\""+cachebrokers[i].cerid+"\"><font>执照</font><em>");
				tstrBrokers.push(cachebrokers[i].cerid);
				tstrBrokers.push("</em></span></dd>");			
				tstrBrokers.push("</dl>");
				
				tstrBrokers.push("<dl class=\"mail_broker_item_open\">");

				tstrBrokers.push("<dt><img src=\""+img+"\" onerror='showImgDelay(this,this.src,2);' /></dt>");		
				tstrBrokers.push("<dd><font>手机</font><em>");
				tstrBrokers.push(cachebrokers[i].mobile);
				tstrBrokers.push("</em><dd><font>性别</font><em>");
				tstrBrokers.push(cachebrokers[i].gender);
				tstrBrokers.push("</em></dd><dd><font>学历</font><em>");
				tstrBrokers.push(cachebrokers[i].edu);
				tstrBrokers.push("</em></dd><dd title=\""+cachebrokers[i].pos+" \"><font>职位</font><em>");
				tstrBrokers.push(cachebrokers[i].pos);
				tstrBrokers.push("</em></dd><dd title=\""+cachebrokers[i].exyears+"年 \"><font>经验</font><em>");
				tstrBrokers.push(cachebrokers[i].exyears+"年");		
				//tstrBrokers.push("</em></dd><dd title=\""+cachebrokers[i].qq+" \"><font>QQ：</font><em>");
				//tstrBrokers.push(cachebrokers[i].qq);			
				tstrBrokers.push("</em></dd><dd title=\""+cachebrokers[i].phone+" \"><font>固话</font><em>");
				tstrBrokers.push(cachebrokers[i].phone);			
				tstrBrokers.push("</em></dd></dl></div>");
				n++;
			}							
			cacheindex++;
			if (cacheindex >= cachebrokers.length) break;
		}	
		//$("#brokerlist").html(strBrokers.join(""));
		if(m>0) {
			$("#brokerlist").html(strBrokers.join(""));
		}
		if(n>0) {
			if(m==0) {
				$("#brokerlist").html(tstrBrokers.join("")); 
			} else {
				$("#brokerlist").append(tstrBrokers.join("")); 
			} 
		}

		if (cacheindex < cachebrokers.length) {
			NeedLoadbrokers = true;
			$(".mail_broker_item").each(function(i,div) {
				if(i%2 == 0)
				{
					$(this).css("background","#e8f3fd");
				}
				if(i == 0)
				{
					$(this).find("img:eq(0)").attr("src","img/ss_mail_icon4.gif");
					$(div).find(".mail_broker_item_open").show();
					$(div).height(201);
				}
			});	
			//setTimeout("DelayLoadbrokers()", 5);
		}
		else
		{
			NeedLoadbrokers = false;
			$("#txtCheckAll").attr("style","");
			showbrokerlistcontrol();//设置经纪人显示和隐藏
			//ListEndchkbrokers();//判断右侧勾选
		}
	}
}

function changeBroker(bid, qsid){
	//var url = "http://192.168.3.128:8080/investAnalysisPlate/qs/initMain.do";
	var url = G_TGPATH() + "qs/initMain.do";
	url += "?qsid="+qsid+"&bid=" + bid ;
	openMain(url);
}
function openMain(param)
{
	var obj = client_core_interface_config();
	var data = obj.r("S_View_Goto","WEBCOMM\r\n" + "URL=("+param+")");
	data = null;
	obj = null;
}

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

//控制经纪人列表显示和隐藏
function showbrokerlistcontrol()
{
	$(".mail_broker_item").each(function(i,div) {
		if(i%2 == 0)
		{
			$(this).css("background","#e8f3fd");
		}		
		//if(i == 0) {
			//$(this).find("img:eq(0)").attr("src","img/ss_mail_icon4.gif");
			$(div).find(".mail_broker_item_open").show();
			//$(div).height(201);
		//}
		/*$(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_broker_item_open").show();
				//$(div).height(201);
			}
			else
			{	
				$(this).attr("src","img/ss_mail_icon3.gif");
				$(div).children(".mail_broker_item_open").hide();
				//$(div).height(52);	
				
			}
		});*/
	});	
}

function chgDivSender(val, cls) {
	$(val).find("input[class='"+cls+"']").each(function(){if(this.checked) {this.checked = false;}else {this.checked=true}chgSender(this);})
}

function chgSender(value)
{
	var txtsenderid = "#txtSender";	
	var sendername = $.trim($(txtsenderid).text()).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 != "";});		
		$(txtsenderid).text(sendername.join(";"));
	}
	else
	{
		$(txtsenderid).text(sname);
	}
}

function allsender(obj, str)
{	
	if(obj.checked)
	{
		//$(obj).parent().parent().parent().parent().find("input").each(function(){this.checked = true;chgSender(this);})
		$(obj).parent().parent().parent().parent().find("input[class='"+str+"']").each(function(){this.checked = true;chgSender(this);})
	}
	else
	{
		//$(obj).parent().parent().parent().parent().find("input").each(function(){this.checked = false;chgSender(this);})
		$(obj).parent().parent().parent().parent().find("input[class='"+str+"']").each(function(){this.checked = false;chgSender(this);})
	}
}

function getSender()
{
	var sender = "";
	var yesno = -1;
	var text = $("#txtSender").text();
	if($.trim(text) == "")
	{
		return sender;
	}
	if(brokersData.length > 0)
	{		
		var textTmp = text.split(";");
		$.each(textTmp,function(i,txt){
			var flag = false;
			for (var i=0; i < brokersData.length; i++)
			{
				var broker = this.split(",");
				var id = brokersData[i].id;			
				if(txt == brokersData[i].nm)
				{
					yesno = sender.indexOf(id);				
					if(yesno < 0)
					{					
						sender += id + ";";
					}
					flag = true;
					break;	
				}			
			}
			if(flag == false)
			{
				yesno = sender.indexOf(txt);				
				if(yesno < 0)
				{					
					sender += txt + ";";
				}
			}
		});
		sender = sender.substring(0,sender.length-1);
		return sender;
	}
	else
	{
		return text;
	}
}

function sendNormal()
{
	var Action = "sender";
	var Senders = getSender();//$("#txtSender").val();
	log.info(Senders);
	if (Senders == "")
	{
		alert("请选择收件人");
		return;
	}
	var sTitle = $("#txtTitle").val().replace(/(^\s*)|(\s*$)/g, "")
	if (sTitle == "")
	{
		alert("标题不能为空，请填写！");
		return;
	}
	if (sTitle.length >200)
	{
		alert("标题内容过多，请填写少于200个字符！");
		return;
	}
	var sMailbody = ifrmwrEditor.getContent();	
	sMailbody=checkimgstrip(sMailbody);
	if (G_TOTALIMGSIZE() < total_imgsize)
	{
		alert("正文中插入的图片过多!图片总大小不得大于5M");
		return;
	}
	CreateMailXML(Action,Senders.toLowerCase(),sTitle,sMailbody);
}

function CreateMailXML(Action,Senders,sTitle,sMailbody)
{
	    $.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)
			{
				nd_type.text(sourceSeq+","+sourceType);
				nd_type.attr("no","2");
				extra = "type=2&source=" + sourcesrvSeq + "&sourcetype=" + sourceType;
			}
			else
			{
				nd_type.attr("no","0");
				extra = "type=0";
			}				
			nd_from.text(getAccountid());
			var ofrom = loadCustomerBase("3",false);
			nd_from.attr("name",ofrom["info"].nm);
			if (Senders == "")
			{
				alert('请输入收件人！');
				//$('#txtTo').focus();
				return;
			}
			else
			{
				nd_to.text(Senders);
			}
			nd_to.attr("name",$("#txtSender").text());
			$($(xml).find("title")[0]).text(encodeString(sTitle));
			$($(xml).find("content")[0]).text("<![CDATA[" + sMailbody + "]]>");			
			var smail = ql_xml_xmltostring(xml);
			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 == "0"  || mySeq == "")
			{
				alert("意外失败！");
				return;
			}
			SetAttrib(mySeq + "\r\n65536");
			if (NewEmailSeq == mySeq)
			{
				if(sourceSeq != "" && sourceSeq != undefined)
				{
					g_sendlogtype = "A3";
					g_sendlogtxt = ","+sourceSeq+","+sourceType+","+sourceFrom;
				}
				else
				{
					var tmpSenders = Senders.split(";");
					g_sendlogtype = "A4";
					g_sendlogtxt = ","+sourceSeq+","+sourceType+","+sourceFrom;
					g_senders = tmpSenders;
				}
				if (NewEmailSeq == SendMail(NewEmailSeq))
				{
					sendprocess = setTimeout("sendfail()",15000);
					popupDiv("dvWait");				
				}
				else
				{
					popupDiv("dvWait");
					sendMailMessage("-3");//发送失败
				
				}					
			}
			else
			{
				popupDiv("dvWait");
				sendMailMessage("-3");//发送失败
			}
		}
    })
}
//清空界面数据
function clearMail()
{ 
	$("#txtSender").text("");
	$("#txtTitle").attr("value","");
	$("#msgcontent").attr("value","");
	$("#txtCheckAll").removeAttr("checked");	
	$("#brokerlist").find("input").each(function(){
		this.checked = false;
	})
}

//进度条
function popupDiv(div_id) 
{		
	$("#" + div_id).css({ 
    	position: "absolute", 
    	left: ($(window).width() - $("#" + div_id).outerWidth())/2, 
    	top: ($(window).height() - $("#" + div_id).outerHeight())/2 
    });	
	$("#" + div_id).show();
	if(div_id=="dvWait")
	{	
		$("#dvWait_bg").show();		
		sendMailMessage("1");
		setTimeout("showtime(1)",1000); 
	}
}

//发送邮件成功失败提示
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 (g_sendlogtype == "A4")
			{
				$.each(g_senders,function(i,txt){																			
					write_log("A4",g_gid + "," +txt+",0");
				});						
			}
			else
			{
					write_log(g_sendlogtype,g_gid + g_sendlogtxt);
			}
			setTimeout("closeWindow()",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;
	}

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

function hideDiv(div_id)
{ 
	$("#" + div_id).hide();
	if(div_id=="dvWait")
	{	
		$("#dvWait_bg").hide();
	}
}

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

function cancelFocus()
{
	$('#txtSender').blur();
}

function myload(){	
//	insertEditor("spwrEditor","","wrEditor","418","317");
	
	clearMail();
	hideDiv('dvWait');
	showbrokerlist();	 	
	var p = new Poly9.URLParser(window.location.href);
	Oparamter = p.getQuerystring().toLowerCase();
	var seq = p.getParameter("seq");
	var pre = p.getParameter("pre");
	var um =p.getParameter("um");
	if(seq != "" && pre=="popmail.htm")//回复
	{
		ReadMail(seq);
	}
	//初始化iframe，并获取编辑框对象
//	initEditor("500px");
//	ifrmwrEditor = 	EDiaryEditor.iframe.contentWindow;
//	ifrmwrEditor.document.body.innerHTML=g_content;
	ifrmwrEditor.setContent(g_content);//设置富文本为默认值
//	$EDITORUI["edui22"]._onClick();//设置纯文本选中
	if(um!="")
	{
		$("#txtSender").text(um);
		chkBrokers(um);
		ListEndchkbrokers();//判断右侧勾选
	}
	NewEmailSeq = NewMail();	
	initpastesetting(1);//设置客户端邮件复制模拟ctr+v
	$("#txtTitle").focus();
}


function myunload()
{
	initpastesetting(0);	//设置客户端邮件复制不模拟ctr+v
}
/*
*利用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;
}