<script type="text/javascript">
    var currObj;
    function uploadImage() {
        if ($("#userfile").val() == '') {
            alert("请选择要上传的文件");
            return false;
        }
        $(document).ready(function () {
            var options = {
                url: '<?= site_url("upload/do_upload") ?>',
                type: "POST",
                dataType: "script",
                beforeSubmit: processBefore,
                success: processReturn,
                error: processError
            };
            $("#uploadfm").ajaxSubmit(options);
            return false;
        });
    }

    function processBefore() {
        $("#upload_msg").text("当前状态:上传文件中,请耐心等待.");
    }

    function processReturn(data) {
        ch = new Array;
        ch = data.split("|");
        //alert(ch[0]);
        if (ch[0] == 'ok') {
            $("#" + currObj).val(ch[1]);
            $("#upload_msg").text("当前状态:空闲");
        } else {
            $("#" + currObj).val(ch[1]);
            $("#upload_msg").text("" + ch[1]);
        }
        $("#upload_msg").text("完成上传,点击关闭即可");
    }
    function processError(data) {
        ch = new Array;
        ch = data.responseText.split("|");
        //alert(ch[0]);
        if (ch[0] == 'ok') {
            $("#" + currObj).val(ch[1]);
            ///$("#upload_msg").text("当前状态:空闲");
        } else {
            $("#" + currObj).val(ch[1]);
            $("#upload_msg").text("" + ch[1]);
        }
        $("#upload_msg").text("完成上传,点击关闭即可");
    }

    function setCurrObj(obj) {
        currObj = obj;
        opendivshow();
    }

    function opendivshow() {

        $('#uploadDiv').show();
        //$('#uploadDiv').attr("");
        //$('#uploadDiv').style.marginLeft = -(500 / 2) + "px";
        $('#fadeshow').show();
    }
    function closedivshow()
    {
        $("#uploadDiv").hide();
        $("#fadeshow").hide();
    }
</script>
<style type="text/css">
    .div_overlay{
        display: none;
        position: fixed;
        top: 0%;
        left: 0%;
        width: 100%;
        height: 100%;
        background-color: black;
        z-index:1010;
        -moz-opacity: 0.8;
        opacity:.80;
        filter: alpha(opacity=80);
    }
    .div_content {
        display: none;
        position: fixed;
        top: 50%;
        left: 50%;
        width: 400px;
        margin-left:-140px;
        height: 200px;
        margin-top:-80px;
        padding: 0;
        border: 2px solid #3777BC;
        background-color: #ffffff;
        _position:absolute;
        z-index:1011;
        overflow: hidden;
    }

</style>
<div id="uploadDiv" class="div_content">
    <div style="width:100%;font-weight:bold;background: #eeeeee;">文件上传<span style="float:right;text-align:right;"><a href="javascript:closedivshow();">关闭</a></span></div>
    <div >
        <span style="font-size:12px;">允许jpg/gif/png/bmp格式文件，容量不超过2M。</span><br>
        <span style="font-size:12px;color:red;">上传方法：先选择文件再点击上传按钮。</span><br>
        <form action="upload.do" name="uploadfm" id="uploadfm" method="post" enctype="multipart/form-data" >
            <input name="userfile"  type="file" id="userfile" size="30" />
        </form>
        <input onclick="uploadImage();" value="上传" type="button" style="border:1px solid green;font-size:16px;margin-top:5px;"/>

    </div>
    <br/>
    <div  id="upload_msg" style="font-size:16px;color:green;font-weight: bold;padding-bottom: 0px;">当前状态：空闲</div>
</div>
<div id="fadeshow" class="div_overlay"></div>
