<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<script type="text/javascript">
    if (editorpath ==undefined)
    {
       var editorpath = '<%=ViewData["Webd"]%>editors/';
    }
    $(document).ready(function(){cfm<%=ViewData["idname"]%>();}); 
    function cfm<%=ViewData["idname"]%>() {
        var newElem = document.getElementById("filediv<%=ViewData["idname"]%>");
        newElem.innerHTML = "";
         var frm = document.createElement("iframe");
             frm.setAttribute("name", "ifr<%=ViewData["idname"]%>");
             frm.setAttribute("id", "ifr<%=ViewData["idname"]%>");
			 frm.setAttribute("src", "");
			 frm.setAttribute("marginwidth", "0");
			 frm.setAttribute("marginheight", "1");
			 frm.setAttribute("width", "310");
			 frm.setAttribute("height", "21");
			 frm.setAttribute("scrolling", "no");
			 frm.setAttribute("border", "0");
			 frm.setAttribute("frameborder", "0");
             /*var frm = document.createElement("<iframe  name='ifr' id='ifr' src='' marginwidth='' marginheight='1' width='260' height='25' scrolling='no' border='0' frameborder='0'></iframe>");  //chrome不支持*/
        newElem.appendChild(frm);
        var ifr<%=ViewData["idname"]%> = window.frames['ifr<%=ViewData["idname"]%>'];
        createcfm<%=ViewData["idname"]%>(ifr<%=ViewData["idname"]%>);
    }
    function createcfm<%=ViewData["idname"]%>(ifr) {        
        ifr.document.open();
        //  ifr.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n');//会提示没有权限
        ifr.document.write('<html>\n');
        ifr.document.write('<head>\n');
        ifr.document.write('<meta http-equiv="Content-Type" content="text/html; charset=gb2312">\n');
        ifr.document.write('<style>*{margin:0px;padding:0px;font-size:12px;line-height:16px;}</style>\n');
        ifr.document.write('<script>function check(){if (document.form1.file1.value==""){window.parent.pdfprocess(false);alert("上传文件不能为空");return false;}\n');
        ifr.document.write('if (window.parent.document.getElementById("<%=ViewData["inputname"]%>").value!=""){window.parent.pdfprocess(false);alert("不能重复上传!");return false;}\n');
        ifr.document.write('window.parent.pdfprocess(true);document.form1.submit();}<\/script>\n');
        ifr.document.write('</head>\n');
        ifr.document.write('<body>\n');
        ifr.document.write('<form id="form1" name="form1" method="post" enctype="multipart/form-data"  action="' + editorpath + 'uploadinc/Upmvc.aspx?idname=<%=ViewData["idname"]%>&w=<%=ViewData["width"]%>&type=4&extname=<%=ViewData["extname"]%>">\n');
        ifr.document.write('<input type="file" name="file1" onchange="check()"  id="file1" value=""></form>');
        ifr.document.write('</body>\n');
        ifr.document.write('</html>');
        ifr.document.close();
    }
    var fileupstate;
    function getpagestate() {
      try{
          var ccc=window.frames['ifr<%=ViewData["idname"]%>'].document.getElementById("file1").value;
       }
       catch(e)
       {
          clearInterval(fileupstate);//stop 
          $("#wrapshow").hide();
          alert("传输被中断！可能是网速原因或者网络问题，请重试！");           
          cfm<%=ViewData["idname"]%>();         
       }
    }
    function parentcfm<%=ViewData["idname"]%>(str,extname) {
        pdfprocess(false);
        if (str!="")
        {
            var webd = '<%=ViewData["Webd"]%>';
            switch(extname)
            {
            case "jpg" :
                var imgstr = '<img src="' + webd + str + '"  onload="javascript:if(this.width>380){this.width=380;}"   alt="" />';
                break;
            case "pdf":
                var imgstr = '<span style="color:#2970D8;">PDF文件上传成功！这里不能预览PDF图片.</span>';
                break;
            case "flv":
                var imgstr = '<span style="color:#2970D8;">视频文件已上传.</span>';
                break;
            case "rar":
                var imgstr = '<span style="color:#2970D8;">文件已上传.</span>';
                break;
            case "doc":
                var imgstr = '<span style="color:#2970D8;">作品附件文件已上传.</span>';
                break;
            default:
                var imgstr = '<img src="' + webd + str + '"  onload="javascript:if(this.width>380){this.width=380;}"   alt="" />';
                break;
            }           
            var picsmall = '#<%=ViewData["inputname"]%>';
            $(picsmall).val(str); //赋值完
            document.getElementById('smallpic<%=ViewData["idname"]%>').innerHTML = imgstr;
          //  document.getElementById('smalldel<%=ViewData["idname"]%>').innerHTML = '<a  onclick="delsmall<%=ViewData["idname"]%>(\'' + str + '\');" href="#">删除</a>';
            //cfm<%=ViewData["idname"]%>();
        }
       // window.frames['ifr<%=ViewData["idname"]%>'].history.go(-1);
       cfm<%=ViewData["idname"]%>();

    }

    function delsmall<%=ViewData["idname"]%>(path) {
        $.ajax({
            type: "POST",
            url: "<%=ViewData["Webd"]%>Services/deletefile",
            dataType: "html",
            data: { "p": "" + path + ""}, //p传输的参数
            success: function(html) {
            if (html != "0") {
                    alert("文件删除成功")
                    document.getElementById('<%=ViewData["inputname"]%>').value = "";
                    document.getElementById('smallpic<%=ViewData["idname"]%>').innerHTML = "";
                }
            }, error: function(html) { alert("error-$.ajax"); }
        });
    }
    function showsmall<%=ViewData["idname"]%>(str) {
        if (str != "") {
            var webd = '<%=ViewData["Webd"]%>';
            var imgstr = '<img src="' + webd + str + '" onload="javascript:if(this.width>380){this.width=380;}" alt="" />';
            document.getElementById('smallpic<%=ViewData["idname"]%>').innerHTML = imgstr;
            //document.getElementById('smalldel<%=ViewData["idname"]%>').innerHTML = '<a  onclick="delsmall<%=ViewData["idname"]%>(\'' + str + '\');" href="#">删除</a>';
            try{
            showpic();
            }
            catch(e)
            {
               
            }
            finally
            {
            }
        }
    }
</script>
<div style="padding-bottom:3px;"><input name='<%=ViewData["inputname"]%>' id="<%=ViewData["inputname"]%>" type="text" readonly="readonly"  value="<%=ViewData["upurl"].ToString()%>" style="width:180px;" /> <span id="smalldel<%=ViewData["idname"]%>"></span></div>
<div id="filediv<%=ViewData["idname"]%>" class="filediv"><span></span></div>
<div id="smallpic<%=ViewData["idname"]%>"></div>

<%if (ViewData["upurl"].ToString() != "")
  {%>
 <script type="text/javascript">showsmall<%=ViewData["idname"]%>('<%=ViewData["upurl"].ToString()%>');</script>
  <%} %>


<div id="wrapshow">
    <div id="wrapbg"><span></span></div>  
    <div id="wrap">
     <div  id="popup">
         <img src="<%=ViewData["webd"]%>Content/themes/basic/images/uploading.gif" alt="" height="12" align="middle" />
         <br />
          正在上传,请稍候……
         <!--<div id="closewin"><span></span></div>-->
     </div>
    </div>   
</div> 