<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Upallfiles.ascx.cs" Inherits="Mvcb2b.admin.controls.Upallfiles" %>
<div ><input name="map_txt" id="map_txt" type="text"  runat="server" value="" style="width:150px; background-color:#f5f5f5;" />
<span id="mapdel<%=Upid %>"></span></div>
<div id="filedivmap<%=Upid %>" class="filediv3"><span></span></div>
<div id="mappic<%=Upid %>"></div>
<script type="text/javascript">
    var editorpathmap = "<%=Webd%>editors/"
    $(document).ready(function(){cfmmap<%=Upid %>();}); 
    function cfmmap<%=Upid %>() {
        var  newElem = document.getElementById("filedivmap<%=Upid %>");
        newElem.innerHTML = "";
        var frm = document.createElement("iframe");
             frm.setAttribute("name", "ifrmap<%=Upid %>");
             frm.setAttribute("id", "ifrmap<%=Upid %>");
			 frm.setAttribute("src", "");
			 frm.setAttribute("marginwidth", "0");
			 frm.setAttribute("marginheight", "1");
			 frm.setAttribute("width", "305");
			 frm.setAttribute("height", "25");
			 frm.setAttribute("scrolling", "no");
			 frm.setAttribute("border", "0");
			 frm.setAttribute("frameborder", "0");
        newElem.appendChild(frm);
        var ifrmap = window.frames['ifrmap<%=Upid %>'];
        createcfmmap<%=Upid %>(ifrmap);
    }
    function createcfmmap<%=Upid %>(ifrmap) {
        ifrmap.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');//会提示没有权限
        ifrmap.document.write('<html>\n');
        ifrmap.document.write('<head>\n');
        ifrmap.document.write('<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />\n');
        ifrmap.document.write('<style>*{margin:0px;padding:0px;line-height:20px;}body{}</style>\n');
        ifrmap.document.write('<script>function check(){if (document.form.upfile.value==""){alert("上传文件不能为空");return false;}if (window.parent.document.getElementById("<%=map_txt.ClientID %>").value!=""){alert("请先删除图片");return false;}}<\/script>\n');
        ifrmap.document.write('</head>\n');
        ifrmap.document.write('<body>\n');
        ifrmap.document.write('<form id="form" name="form" method="post" enctype="multipart/form-data" onsubmit="return check();" action="' + editorpathmap + 'uploadinc/Upallfiles.aspx?w=<%=Width%>&upid=<%=Upid %>&tablename=<%=Tablename %>&extname=<%=Extname%>">\n');
        ifrmap.document.write('<input type="file" name="upfile"  id="upfile" value="" style="width:180px;line-height:20px;margin-top:2px;height:19px;" /><input style="padding-left:3px;padding-right:3px;height:21px;line-height:18px;width:73px;"  type="submit" name="Submit3" value="开始上传" /></form>');
        ifrmap.document.write('</body>\n');
        ifrmap.document.write('</html>');
        ifrmap.document.close();
    }
    function parentcfmmap<%=Upid %>(str,extname) {

        var webd = "<%=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 "exe":
            var imgstr = '<span style="color:#2970D8;">文件已上传.</span>';
            break;
        case "doc":
            var imgstr = '<span style="color:#2970D8;">文件已上传.</span>';
            break;
        case "txt":
            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 = "#<%=map_txt.ClientID %>";
        $(picsmall).val(str); //赋值完
        document.getElementById("mappic<%=Upid %>").innerHTML = imgstr;
        document.getElementById("mapdel<%=Upid %>").innerHTML = '<a  onclick="delmap<%=Upid %>(\'' + str + '\');" href="javascript:void(0);">删除</a>';
        cfmmap<%=Upid%>();
        /*
        window.frames['ifrmap-Upid-'].history.go(-1);不支持chrome
        return false;
        */
    }
    function delmap<%=Upid %>(path) {
        if (confirm('确实要删除吗?')) {
            $.ajax({
                type: "POST",
                url: "jquery/Delsmallpic.aspx",
                dataType: "html",
                data: { "p": "" + path + "" }, //p传输的参数
                success: function(html) {
                    if (html != "0") {
                        alert("文件删除成功")
                        document.getElementById("<%=map_txt.ClientID %>").value = "";
                        document.getElementById("mappic<%=Upid %>").innerHTML = "";
                    }
                }, error: function(error) { alert("没有权限!ERROR:"+error+path); }
            });
        }
    }

    function showmap<%=Upid %>(str) {
        if (str != "") {
            var webd = "<%=Webd%>";
            <%switch (Extname)
            {   
                 case "pdf":%>
            var imgstr = '<span style="color:#2970D8;">PDF图片已存在,这里不能预览.</span>';
            <%
                     break;
                 case "jpg":
            %>            
            var imgstr = '<img src="' + webd + str + '" onload="javascript:if(this.width>380){this.width=380;}"  alt="" />';   
            <%
                      break;
                  case "flv":
                  %>            
            var imgstr = '<span style="color:#2970D8;">视频文件已上传.</span>'; 
            <%
                      break;
                  case "rar":
                  %>            
            var imgstr = '<span style="color:#2970D8;">文件已上传.</span>';  
            <%
                      break;
                  case "exe":
                  %>            
            var imgstr = '<span style="color:#2970D8;">文件已上传.</span>';  
            <%
                      break;
                  case "doc":
                  %>            
            var imgstr = '<span style="color:#2970D8;">文件已上传.</span>';  
            <%
                break;
                  case "txt":
                  %>            
            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;
            } %>   

            document.getElementById("mappic<%=Upid %>").innerHTML = imgstr;
            document.getElementById("mapdel<%=Upid %>").innerHTML = '<a  onclick="delmap<%=Upid %>(\'' + str + '\');" href="javascript:void(0);">删除</a>';
            try{
            showpic();/*位于add.aspx页面是否显示图片*/
            }
            catch(e)
            {
               
            }
            finally
            {
            }
        }
    }
</script>
