//var Oparamter = "";
var NewEmailSeq = "";
var sourceSeq = "";
var sourcesrvSeq = "";
var sourceType = "";
var sourceFrom = "";
var sendprocess;
var sendMailTimeState = "false"; //发送邮件计时是否启用
var g_sendlogtype = "";
var g_sendlogtxt = "";
var g_senders = [];
var g_gid = "";
var sSeq = "";
var srvseq = ""; //服务器源邮件编号
var sName = ""; //发件人姓名
var tsattr = ""; //收件箱还是发件箱
var tmpmk = "";
var tmpcode = "";
var tmpcodename = "";
var procuids = "";
var Senders = ""; //当前发送邮件收件人
var SendersNames = ""; //当前发送邮件收件人姓名
var itab = "0"; // 当前邮件发送类型 
var staskid = ""; //代办事项id
var sproductid = ""; //产品id
var sproductname = ""; //产品名称
var batchmail = "false"; //标识是否是批量邮件 true:批量 false:单独；

var ifrmwrEditor; //富文本编辑框的引用
var mytimer = null;
var closetimer = null;
var total_imgsize = 0;
var total_filesize = 0;
var attachfiles = [];

var sourceprodmodetype ="63";//当前发送邮件类别： 模板类型  2：黄金眼短期产品 3：14天试用产品  60:办公类产品 61：投顾服务类产品  62：咨询类产品  63：理财类产品 


//发送超时显示消息
function sendfail() {
    clearTimeout(sendprocess);
    sendMailMessage("-2"); //发送失败（超时）
}
//弹出发送邮件等待提示信息
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 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();
            {
                var rtn = SetTrialRightProductCenter(g_senders.join(","), sproductid, "63", "", "").replace(/\r\n/g, "");
                if (rtn != "1") {
                    alert("邮件发送成功,但" + sproductname + "权限分配操作失败!(" + rtn + ")");
                }
                rtn = batchupdateTask_mail(staskid, g_gid).replace(/\r\n/g, "");
//                if (rtn < 0) {
//                    alert("更新待办事项邮件ID失败！");
//                    return;
//                }
            }
            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);
            }
            RefreshTask(); //待办事项页面刷新
            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) {
    if (sendMailTimeState == "true") {
        $("#dvWait_time").text(time);
        time = time + 1;
        setTimeout("showtime(" + time + ")", 1000);
    }
}
/////////////////////////////////////////////////////////////////////////////////////////
/*
*首次加载
*/
$(function () {
    myload();
});
function myload() {
    mailjs();
    clearMail();
    hideDiv('dvWait');
    var p = new Poly9.URLParser((window.location.href).replace(/%26/g, "&"));
    var ps = p.getQuerystring().toLowerCase();
    var tmpkey = p.getParameter("skey");
    var odata = { "pid": "", "pname": "", "taskId": "", "customerId": "", "customerName": "" };
    //initUsersData();
    load_AllBrokerRight("2", false);
    if (tmpkey == undefined || tmpkey == "") {
        batchmail = "false";
        sSeq = p.getParameter("seq");
        GLOBAL_Seq = sSeq;
        ReadMailex(sSeq);
    } else {
        batchmail = "true";
        var tmpdata = client_data_load(tmpkey, "0");
        if (tmpdata != null) {
            odata = eval('(' + tmpdata.dValue + ')');
        }
        ReadLoadData(odata);
    }
    //判断是不是待办事项调用当前页面    
    NewEmailSeq = NewMail();
    //设置附件鼠标经过事件样式
    $(".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");
    });
    initpastesetting(1); //设置客户端邮件复制模拟ctr+v
}
function myunload() {
    initpastesetting(0); //设置客户端邮件复制不模拟ctr+v
}


//清空界面数据
function clearMail() {
    $("#txtSender").text("");
    $("#msgcontent").attr("value", "");
}
/*
*读取缓存信息
*/
function ReadLoadData(odata) {
    Senders = odata.customerId; //当前发送邮件收件人
    if (Senders == undefined) {
        Senders = "";
    }
    Senders = getsender(Senders);


    SendersNames = odata.customerName; //当前发送邮件收件人姓名
    if (SendersNames == undefined) {
        SendersNames = "";
    }
    SendersNames = getsender(SendersNames);

    sourceType = "";
    sourcesrvSeq = ""; //	取源邮件编号

    staskid = odata.taskId; //代办事项id
    if (staskid == undefined) {
        staskid = "";
    }

    sproductid = odata.pid; //产品id
    if (sproductid == undefined) {
        sproductid = "";
    }
    procuids = sproductid; //产品id

    sproductname = odata.pname; //产品名称
    if (sproductname == undefined) {
        sproductname = "******";
    }

    var tmpstart = odata.startDate;
    if (tmpstart == undefined) {
        tmpstart = "";
    }

    var tmpend = odata.endDate;
    if (tmpend == undefined) {
        tmpend = "";
    }

    $("#txtSender").text(SendersNames);
    $("#txtSender").attr("title", SendersNames);
    // $("#taskstart").val(tmpstart);
    // $("#taskend").val(tmpend);
    $("#txttitle").text(sproductname + "投资建议！");
}

/*
*获取用户或id重复值
*/
function getsender(senddata) {
    var Senders = ";";
    var yesno = -1;
    var sendername = $.trim(senddata).split(";");
    $(sendername).each(function (index) {
        var name = $.trim(sendername[index]);
        yesno = Senders.indexOf(name);
        if (yesno < 0) {
            Senders += name + ";";
        }
    });
    if (Senders.length > 1 && Senders.substring(Senders.length - 1) == ";") {
        Senders = Senders.substring(1, Senders.length - 1);
    }
    return Senders;
}
/*
*读取服务器邮件
*/
function ReadMailex(seq) {
    var text = GetMailex(seq);
    var iFirstContent = text.indexOf("<content><![CDATA[");
    var iLastContent = text.lastIndexOf("]]></content>");
    if ((iFirstContent < 0) || (iLastContent < 0)) {

        alert("本地邮件未收到或已删除！");
        closeWindow();
        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);
    tsattr = sattr.substring(5, 6);
    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 sfrom = $($(xml).find("from")[0]).text();
    GLOBAL_from = sfrom;
    sName = sfrom;
    var tmpsfromName = $($(xml).find("from")[0]).attr("name");
    var sfromName = sfrom;

    if (tmpsfromName != undefined && tmpsfromName != "") {
        sfromName = tmpsfromName;
    }
    Senders = sfrom; //当前发送邮件收件人
    SendersNames = tmpsfromName; //当前发送邮件收件人姓名
    //	var sto = $($(xml).find("to")[0]).text();
    //	var Tos = sto.split(";");
    //	var toName = sto;
    //	var tmpstoName=$($(xml).find("to")[0]).attr("name");	
    //	if(tmpstoName != undefined && tmpstoName != "")
    //	{
    //		toName=tmpstoName;
    //	}
    var stimestamp = $($(xml).find("mail")[0]).attr("timestamp");
    var sattrib = "";
    if ($(xml).find("attrib").length != 0)
        sattrib = $($(xml).find("attrib")[0]).text();
    var stitle = decodeString($($(xml).find("title")[0]).text());
    sourceType = $($(xml).find("type")[0]).attr("no");
    sourcesrvSeq = $($(xml).find("mail")[0]).attr("srvseq"); //	取源邮件编号
    if (sourcesrvSeq == undefined) {
        sourcesrvSeq = "";
    }
    //	var tmpgoldstr=	$($(xml).find("goldcode")[0]).text().split("|")[0];
    staskid = $($(xml).find("producttype")[0]).attr("taskid");
    if (staskid == undefined) {
        staskid = "";
    }
    var tmpproducts = $($(xml).find("producttype")[0]).text();
    sproductid = tmpproducts.split("|")[0]; //产品id
    if (sproductid == undefined) {
        sproductid = "";
    }
    procuids = sproductid;
    sproductname = tmpproducts.split("|")[1]; //产品名称
    if (sproductname == undefined) {
        sproductname = "******";
    }
    
    $("#txtSender").text(sfromName);
    $("#txttitle").text(sproductname + "投资建议！");
}



//关闭窗体写应用回执
function preclose() {

}
//+---------------------------------------------------
//| cookie相关的方法
//+---------------------------------------------------
function setCookie(c_name, value) {
    document.cookie = c_name + '=' + escape(value) + ";path=/";
    return;
}



//隐藏弹出层
function hideDiv(div_id) {
    $("#" + div_id).hide();

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

/*
*itab:1 快速回复，2 带说明回复 3 拒绝回复
*/
function sendNormal() {
    var Action = "sender";
    var userinfo = getSysUser();
    var scid = userinfo[0];
    var sTitle = ""; //邮件标题	
    var sMailbody = ""; //邮件正文
    var procuidates = "";
    var cids = "";
    sTitle = $("#txttitle").text();
    if (sTitle == "") {
        alert("标题不能为空，请填写！");
        return;
    }
    if (sTitle.length > 200) {
        alert("标题内容过多，请填写少于200个字符！");
        return;
    }
    sMailbody = ifrmwrEditor.getContent();
    sMailbody = checkimgstrip(sMailbody); //过滤邮件中img标签

    if (G_TOTALIMGSIZE() < total_imgsize) {
        alert("正文中插入的图片过多!图片总大小不得大于5M");
        return;
    }
    cids = Senders.replace(/;/g, ",");
    CreateMailXML(Action, Senders.toLowerCase(), sTitle, sMailbody, cids, procuids, procuidates, SendersNames);
}

function CreateMailXML(Action, Senders, sTitle, sMailbody, cids, procuids, procuidates, SendersNames) {
    $.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 (batchmail == "false") {
                    extra = "type=0&source=" + sourcesrvSeq + "&sourcetype=" + sourceType;
                    nd_type.text(sourcesrvSeq + "," + sourceType);
                } else {
                    extra = "type=0";
                }
                //extra = "type=0&source=" + sourcesrvSeq + "&sourcetype=" + sourceType;
                nd_type.attr("no", "0");
                if (procuids != "") {
                    nd_type.attr("subno", procuids);
                }
                if(sourceprodmodetype !=""){
                	nd_type.attr("prodtype", sourceprodmodetype);
                }
                //nd_type.text(sourcesrvSeq+","+sourceType);
                $($(xml).find("to")[0]).attr("name", SendersNames);
            }
            nd_from.text(getAccountid());
            nd_from.attr("name", G_broker["info"].nm);
            if (Senders == "") {
                alert("请输入收件人！");
                return;
            }
            else {
                nd_to.text(Senders);
            }
            $($(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 (batchmail == "false") {
                var rtn = updateTask(staskid, "1", "", "", "").replace(/\r\n/g, "");

                if (rtn < 0) {
                    alert("更新待办事项失败！");
                    return;
                } else if (rtn == 0) {
                    alert("待办事项已删除！");
                    return;
                }

            } else {
                var rtn = batchupdateTask(staskid, "1", "", "", "").replace(/\r\n/g, "");

                if (rtn < 0) {
                    alert("批量更新待办事项失败！");
                    return;
                }else if (rtn == 0) {
                    alert("待办事项已删除！");
                    return;
                }
            }

            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 && batchmail == "false") {
                    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 closeMe() {
    clearTimeout(closetimer);
    closeWindow();
}

//**************************************************************添加附件
//清空上传控件
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;");
        //   $("#showattachlist").attr("style", "padding-top: 20px; position: relative;");
        ifrmwrEditor.setHeight(120);
        ifrmwrEditor.body.style.height = "120px";
    }
    else {
        // $("#contentarea").attr("style", "height:270px;");
        //    $("#showattachlist").attr("style", "padding-top: 0px; position: relative;");
        ifrmwrEditor.setHeight(140);
        ifrmwrEditor.body.style.height = "140px";
    }
}
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');
            //   $("#showattachlist").attr("style", "padding-top: 0px; position: relative;");
            ifrmwrEditor.setHeight(120);
            ifrmwrEditor.body.style.height = "120px";
            break;
        default:
            $("#attachmore").show();
        case 2:
            $("#attach2").text(attachfiles[attachfiles.length - 2]["localfilename"]);
            //    $("#showattachlist").attr("style", "padding-top: 20px; position: relative;");
            $("#attach2").show();
            $("#attachdel2").show();

        case 1:
            $("#attach1").text(attachfiles[attachfiles.length - 1]["localfilename"]);
            $("#attach1").show();
            $("#attachdel1").show();
            $("#attachment").show();
            ifrmwrEditor.setHeight(120);
            ifrmwrEditor.body.style.height = "120px";
            //   $("#showattachlist").attr("style", "padding-top: 20px; position: relative;");
            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 + ")");
}
//利用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).replace(/%26/g, "&");
    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;");
    // $("#showattachlist").attr("style", "padding-top: 20px; position: relative;");
    ifrmwrEditor.setHeight(120);
    ifrmwrEditor.body.style.height = "120px";
    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 {

            reloadattachs();
        }
    }
    catch (e) {
        alert("上传失败！");
    }
    ifrmDoc = null;
}
