var bindImg2 = function(id) {
    var currentTime = $("#currentTime").val();
    var uploadEnc = $("#uploadEnc").val();
    var uploadUid = $("#uploadUid").val();

    var buttonId = id;
    var imgs = "images_" + id;
    var uploader = WebUploader.create({
        auto: true,
        swf: '/js/webuploader-0.1.5/Uploader.swf',
        server: ServerHost.uploadDomain + '/upload/edit/upload-image?uid=' + uploadUid + "&enc2=" + uploadEnc+ "&t=" + currentTime,
        compress: false,
        fileSingleSizeLimit: 4*1024*1024,
        withCredentials:true,
        fileVal: 'file',
        pick: {
            id: "#"+buttonId,
            innerHTML:''
        },
        duplicate:true,
        accept: {
            title: 'Images',
            extensions: "jpg,jpeg,gif,png",
            mimeTypes: 'image/*'
        },

        //当文件被加入队列以后触发。
        onFileQueued: uploadQueued,
        //当文件上传成功时触发。
        onUploadSuccess: fileUploaded,
        //当文件上传出错时触发。
        onError: fileQueueError
    });

    function uploadQueued(files) {
        var imgcount = $("#" + imgs).find("img").size();
        var status = uploader.getStats();
        if ((imgcount + status.queueNum) > 20) {
            alert("最多能上传20张图片");
            return false;
        }
    }


    function fileQueueError (type, p1, p2) {
        var errorTitle="上传失败"+type;
        switch (type) {
            case 'Q_EXCEED_NUM_LIMIT':
                errorTitle = "文件数量过多";
                break;
            case 'Q_EXCEED_SIZE_LIMIT':
                errorTitle = "文件过大";
                break;
            case 'Q_TYPE_DENIED':
                errorTitle = "无效的文件类型";
                break;
            case 'F_DUPLICATE':
                errorTitle = "文件重复";
                break;
        }

        alert(errorTitle);
    }

    //当队列中的某一个文件上传完成后触发
    function fileUploaded(file, serverData) {
        var rep = JSON.stringify(serverData);
        uploadLandCover_upload_success_handler2(buttonId, file, rep);
    }
};


var uploadLandCover_upload_success_handler2 = function(id, file, serverData) {
    var imgcount = $("#images_" + id).find("img").size();
    if (imgcount > 20) {
        return;
    }
    try {
        //后台传递回来的内容
        var orgin_url = serverData.split("_")[1];
        var url = orgin_url.replace("/origin/", "/74_89c/");
        var content = $("#images_" + id).html();
        if (id == "fileUploader_group") {
            var in1 = "<li><input type='hidden' name='files' value='"
                + orgin_url
                + "'/><a href='javascript:;'><img src='"
                + orgin_url
                + "'/><a class='delePic' href='javascript:;' onclick='removeinput1(this);'></a></a></li>"
            $("#images_" + id).html(content + in1);
        }
    } catch (ex) {
        this.debug(ex);
    }
}

function getcookie(objname){
    var arrstr = document.cookie.split("; ");
    for(var i = 0;i < arrstr.length;i ++){
        var temp = arrstr[i].split("=");
        if(temp[0] == objname){
            return unescape(temp[1]);
        }
    }
}
var removeinput1 = function(obj){
    var spanObj = jQuery(obj).parent();
    spanObj.remove();
}