﻿function AttachItem() {
    //	var isvalid=true;
    //	var path,name,type,size,desc;
    this.index = -1;
    this.path = "";
    this.name = ""
    this.type = "";
    this.size = -1;
    this.desc = "";
    this.configname = "";
    this.setIndex = AttachItem_setIndex;
    this.getIndex = AttachItem_getIndex;
    
    this.setPath = AttachItem_setPath;
    this.getPath = AttachItem_getPath;

    this.setName = AttachItem_setName;
    this.getName = AttachItem_getName;

    this.setSize = AttachItem_setSize;
    this.getSize = AttachItem_getSize;
    this.getSizeDesc = AttachItem_getSizeDesc;

    this.setValue = AttachItem_setValue;
    this.getValue = AttachItem_getValue;
    this.setConfigName = AttachItem_setConfigName;
    this.doDownload = AttachItem_doDownload;
    this.getDownloadUrl = AttachItem_getDownloadUrl;
}

function AttachItem_setIndex(value) {
    this.index = value;
}
function AttachItem_getIndex(value) {
    return this.index;
}
function AttachItem_setConfigName(value) {
    this.configname = value;
}
function AttachItem_setPath(value) {
    this.path = value;
}
function AttachItem_getPath(value) {
    return this.path;
}

function AttachItem_setSize(value) {
    this.size = value;
}
function AttachItem_getSize(value) {
    return this.size;
}
function AttachItem_getSizeDesc(value) {
    return this.size + "b";
}

function AttachItem_setName(value) {
    this.name = value;
}
function AttachItem_getName() {
    return this.name;
}

function AttachItem_setValue(value) {
    var n;
    var a = value.split("::");
    n = a.length;
    if (n < 3) {
        this.isvalid = false;
        return;
    }
    this.path = a[0];
    this.name = a[1];
    this.type = a[2];
    if (n > 3)
        this.size = parseInt(a[3]);

    if (n > 4)
        this.desc = a[4];

    if (n > 5) {
        this.index = a[5];
    }
    this.isvalid = true;
}
function AttachItem_getValue() {
    return this.path + "::" + this.name + "::" + this.type + "::" + this.size + "::" + this.desc + "::" + this.index;
}
function AttachItem_doDownload() {
    window.open(this.getDownloadUrl());
}
function AttachItem_getDownloadUrl() {
    if (window._g_getattachbyisapi == false) {
        var url = "/public/helper/download.aspx?a=" + this.path + "&b=" + this.name + "&c=application/binary&d=1"
        if (this.configname != "") {
            url += "&e=" + this.configname;
        }
        return url;
    } else {

        var url = "/aisapi/YLGetAttach.dll?GetAttach?a=" + this.path + "&b=" + this.name + "&c=application/binary&d=1"
        if (this.configname != "") {
            url += "&e=" + this.configname;
        }
        return url; //"/aisapi/YLGetAttach.dll?GetAttach?a="+this.path+"&b="+this.name+"&c=application/binary&d=1";

    }
}

function GF_AttachFileDeleteImpl(obj, delfile) {
    if (obj.value != "") {
        var arAttach = obj.value.split("||");
        var file;
        var newFile = "";
        for (var i = 0; i < arAttach.length; i++) {
            file = arAttach[i];
            if (escape(file) != delfile) {
                newFile += "||" + file;
            }
        }
        obj.value = newFile.substr(2);
        //alert(obj.value);
        GF_AttachFileCheckList(obj);
    }
}

function GF_AttachFileCheckListImpl(obj) {
    if ((window.form1 != null) && (window.form1.selAttachlist != null)) {
        var filelist = obj.value;
        _F_LS_Clear(form1.selAttachlist);
        if (filelist != "") {
            var arAttach = filelist.split("||");
            var file;
            for (var i = 0; i < arAttach.length; i++) {
                file = arAttach[i];
                var attachitem = new AttachItem();
                attachitem.setValue(file);
                if (file != "")
                    _F_LS_Add(form1.selAttachlist, attachitem.getName() + "(" + attachitem.getSizeDesc() + ")", file);
            }
        }
        top.window["attach_data"].value = filelist;
    } else {
        if (obj.value != "") {
            GAttachFileCurrent.style.display = "";
            GAttachFileCurrent.style.lineheight = "16px";
            GAttachFileCurrent.innerHTML = ""; //obj.value; 
            var arAttach = obj.value.split("||");
            var file;
            for (var i = 0; i < arAttach.length; i++) {
                file = arAttach[i];
                var attachitem = new AttachItem();
                attachitem.setValue(file);
                if (file != "") {
                    //_F_LS_Add(form1.selAttachlist,attachitem.getName()+"("+attachitem.getSizeDesc()+")",file);
                    GAttachFileCurrent.innerHTML += "<nobr><a href=\"" + attachitem.getDownloadUrl() + "\">" + attachitem.getName() + "</a>&nbsp;<span style=\"text-decoration:underline;cursor:hand;\" onclick='GF_AttachFileDelete(\"" + escape(file) + "\")'>移除</span></nobr>&nbsp;&nbsp;";
                }
            }
        } else {
            GAttachFileCurrent.style.display = "none";
            GAttachFileCurrent.innerHTML = "";
        }
    }
}

