<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Uponenopostpic.ascx.cs" Inherits="Mvcb2b.admin.controls.Uponenopostpic" %>
<div ><input name="picurl_txt" id="picurl_txt" type="text" readonly="readonly" runat="server" value="" style="width:150px; background-color:#f5f5f5;" />
<span id="smalldel"></span></div>
<div id="filediv3" class="filediv3"><span></span></div>
<div id="smallpic"></div>

<div id="wrapshow2">
    <div id="wrapbg2"><span></span></div>  
    <div id="wrap2">
     <div  id="popup2" >
         <img src="images/uploading.gif" alt="" height="12" align="middle" />
         <br />
          正在上传,请稍候&hellip;&hellip;
         <!--<div id="closewin"><span></span></div>-->
     </div>
    </div>   
</div> 


<div id="wrapshow_size">
    <div id="wrapbg_size"><span></span></div>  
    <div id="wrap_size">
     <div  id="popup_size" >     
         <div  class="size_msg">
             总大小: <span id="Filesize_msg">0Mb</span>  <br />
             已上传: <span id="Havesize_msg">0Mb</span>  <br />
             上传速率：<span id="Perspeed_msg">0KB</span>/S<br />
             <span id="Status_msg">剩余时间： <span id="Time_msg">正在计算……</span></span>
         </div>  
         <div class="upbg"><div class="upfinish"><span></span></div></div>
         <div class="fini">完成 <span id="finish_msg">0%</span></div>
         <div id="closewin_size"><span></span></div>
     </div>
    </div>   
</div> 
 
<script type="text/javascript">
    var webd="<%=Webd%>";
    var editorpath2 = webd+"editors/";    
    $(document).ready(function(){     
       cfm3();
       $("#closewin_size").click(function(){
           $("#wrapshow_size").hide();
       });
     });     
	var fileupstate;
    var IsISAPI="<%=IsISAPI%>";
    function pdfprocess(flag) {		 
         try{
           if (flag==true)
           {
              if (IsISAPI=="True")
              {
			   $("#wrapshow_size").show();
               $("#closewin_size").show();
               $.post(sessionurl); //清空
               if ($("#Status_msg").html()=="状态：上传成功!")
               {
                    $("#Filesize_msg").html("0Mb");
				    $("#Havesize_msg").html("0Mb");
				    $("#Perspeed_msg").html("0KB");
                    $("#finish_msg").html("0%");
                    $("#popup_size .upfinish").css("width","0%");	
                    $("#Status_msg").html('剩余时间： <span id="Time_msg">正在计算……</span>');
                }
			    fileupstate = window.setInterval("getfilestate()",800);  
              }
              else
              {
                $("#wrapshow2").show();  
			    fileupstate = window.setInterval("getnetstate()",800); 
              }
           }
           else
           {
              $("#wrapshow2").hide();
           }
         }
         catch(err){}
    }
	function getnetstate() {
		  try{
			  var ccc=window.frames['ifr3'].document.getElementById("file3").value;    	
		  }
		  catch(e)
		  {
			  clearInterval(getnetstate);//stop 
			  $("#wrapshow2").hide();
			  alert("传输被中断！可能是网速原因或者网络问题，请重试！");           
			  cfm3();  
		  }
    }
    
    var getfilesize=webd+"Jqueryfile/GetFileSize.aspx";
    var sessionurl=webd+"Jqueryfile/SessionEmpty.aspx?sessionid=<%=Sessionid%>";
    function getfilestate() {   
        try{        
                  //显示进度条          
                  $.ajax({
                    type: "POST",
                    url: getfilesize,
                    dataType: "json",
                    data: { "action": "show" },
                    success: function (json) {
                         var flag=false;
                         if (json!=null)
                         {
                             var info=json.fileinfo;	
                             if (info!=null)
                             {
                     	         var AllTime=info[0].AllTime;
                                 var Filesize=parseFloat(info[0].Filesize);
                                 var Havesize=parseFloat(info[0].Havesize);
                                 var Percentwidth=parseInt(info[0].Percentwidth);
                                 var Perspeed=parseFloat(info[0].Perspeed);
                                 var Nowtimestr=info[0].Nowtimestr;
                                 var Totals=parseInt(info[0].Totals); 
                                 flag=true;
						 
						         //show info
                                 var Filesize_msg="",Havesize_msg="",Perspeed_msg="";
                                 $("#popup_size .upfinish").css("width",Percentwidth+"%");	
						         if (Filesize/1024>1)
						             Filesize_msg=(Filesize/1024).toFixed(3)+"MB";		
					             else
						             Filesize_msg=Filesize.toFixed(2)+"KB";		
						         if (Havesize/1024>1)
						             Havesize_msg=(Havesize/1024).toFixed(3)+"MB";		
					             else
						             Havesize_msg=Havesize.toFixed(2)+"KB";	
						         if (Perspeed/1024>1)
						             Perspeed_msg=(Perspeed/1024).toFixed(3)+"MB";		
					             else
						             Perspeed_msg=Perspeed.toFixed(2)+"KB";		
							 
						         //秒
					             var yutime=parseFloat(Filesize-Havesize)/Perspeed;   
                                  //alert(yutime);
						         var hour=0,minu=0,seco=0,timemsg="";
						         if (yutime>=3600)
						         {
						             hour=parseInt(yutime/3600); 
							         if (hour>0)
							            timemsg=hour +"小时 ";
						         }
						         if (yutime>=60)
						         {
						             minu=parseInt((yutime%3600)/60);
							         if (minu>0)
							            timemsg=timemsg+" "+minu +"分钟 ";
						         }
						         seco=parseInt(yutime%60);
						         if (seco>0)
							         timemsg=timemsg+" "+seco +"秒 ";
                       
						         $("#Filesize_msg").html(Filesize_msg);
						         $("#Havesize_msg").html(Havesize_msg);
						         $("#Perspeed_msg").html(Perspeed_msg);
                                 $("#finish_msg").html(Percentwidth+"%");
						         $("#Time_msg").html(timemsg);
                                 if (Percentwidth==100) 
                                 {
                                  clearInterval(fileupstate);//stop 
						          $("#Status_msg").html("状态：上传成功!");
                                  $("#closewin_size").show();
                                  $.post(sessionurl); //清空
                                 }

                             }
                         }
                    },error: function (err) {
                        clearInterval(fileupstate);//stop
                        $("#wrapshow_size").hide();                        
                        alert("网速太慢! 传输被中断！Ajax错误!");
                        cfm3();  
                        $.post(sessionurl); //清空
			        }
                   });
          }
		  catch(e)
		  {
			  clearInterval(getnetstate);//stop 
			  $("#wrapshow_size").hide();
			  alert("传输被中断！可能是网速原因或者网络问题，请重试！");           
			  cfm3();  
              $.post(sessionurl); //清空
		  }
    }
    function cfm3() {
        var newElem = document.getElementById("filediv3");
        newElem.innerHTML = "";
        var frm = document.createElement("iframe");
        frm.setAttribute("name", "ifr3");
        frm.setAttribute("id", "ifr3");
        frm.setAttribute("src", "");
        frm.setAttribute("marginwidth", "0");
        frm.setAttribute("marginheight", "1");
        frm.setAttribute("width", "260");
        frm.setAttribute("height", "25");
        frm.setAttribute("scrolling", "no");
        frm.setAttribute("border", "0");
        frm.setAttribute("frameborder", "0");
        newElem.appendChild(frm);
        var ifr3 = window.frames['ifr3'];
        createcfm3(ifr3);
    }


    function createcfm3(ifr) {
        ifr3.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');//会提示没有权限
        ifr3.document.write('<html>\n');
        ifr3.document.write('<head>\n');
        ifr3.document.write('<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />\n');
        ifr3.document.write('<style>*{margin:0px;padding:0px;line-height:20px;}body{}</style>\n');
        ifr3.document.write('<script>function check(){if (document.form2.file3.value==""){window.parent.pdfprocess(false);alert("上传文件不能为空");return false;}if (window.parent.document.getElementById("<%=picurl_txt.ClientID %>").value!=""){window.parent.pdfprocess(false);alert("请先删除图片");return false;}window.parent.pdfprocess(true);}<\/script>\n');
        ifr3.document.write('</head>\n');
        ifr3.document.write('<body>\n');
        ifr3.document.write('<form id="form2" name="form2" method="post" enctype="multipart/form-data" onsubmit="return check();" action="' + editorpath2 + 'uploadinc/Uponepic.aspx?w=<%=Width%>&ispdf=<%=Ispdf%>&sessionid=<%=Sessionid%>">\n');
        ifr3.document.write('<input type="file" name="file3"  id="file3" 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" id="submit3" value="开始上传" /></form>');
        ifr3.document.write('</body>\n');
        ifr3.document.write('</html>');
        ifr3.document.close();
    }
    /*below for upload pic */
    function parentcfm3(str,picid) {
        var imgstr = '<img src="' + webd + str + '"  onload="javascript:if(this.width>380){this.width=380;}"   alt="" />';
        var picsmall = "#<%=picurl_txt.ClientID %>";
        $(picsmall).val(str); //赋值完
        $("#smallpic").html(imgstr);
        $("#smalldel").html('<a  onclick="delsmall(\'' + str + '\');" href="javascript:void(0);">删除</a>');
        cfm3();
    }
    /*below for ispdf=1*/
    function parentcfm3pdf(str,picid) {
       pdfprocess(false);
       var imgstr = '<span style="color:#2970D8;">PDF文件上传成功！这里不能预览PDF图片.</span>';
       var picsmall = "#<%=picurl_txt.ClientID %>";0
       
       $(picsmall).val(str); //赋值完
       $("#smallpic").html(imgstr);
       $("#smalldel").html('<a  onclick="delsmall(\'' + str + '\');" href="javascript:void(0);">删除</a>');       
       cfm3();
    }  

    function delsmall(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("<%=picurl_txt.ClientID %>").value = "";
                         $("#smallpic").html("");
                    }
                }, error: function(html) { alert("没有权限!"); }
            });
      }
    }

    function showsmall(str) {
        if (str != "") {
            var webd = "<%=Webd%>";
            var imgstr="";
            <%if (Ispdf=="1")
            {%>
            imgstr = '<span style="color:#2970D8;">PDF图片已存在,这里不能预览.</span>';
            <%}
            else
            {%>            
            imgstr = '<img src="' + webd + str + '" onload="javascript:if(this.width>380){this.width=380;}"  alt="" />';   
            <%} %>         
            $("#smallpic").html(imgstr);
            $("#smalldel").html('<a  onclick="delsmall(\'' + str + '\');" href="javascript:void(0);">删除</a>');
            try{
            showpic();
            }
            catch(e)
            {
               
            }
            finally
            {
            }
        }
    }
</script>
