<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Upcon.ascx.cs" Inherits="Mvcb2b.admin.controls.Upcon" %>
<script type="text/javascript">
    function parentcfm(str, picid) {
        //var imgstr = '<img src=&quot;' + str + '&quot; alt=&quot; &quot;  />'; //单引号 &apos; 双引号：&quot;
        var imgstr = '<p><img src="' + str + '" alt="" width="480"  /></p>'; //单引号 &apos; 双引号：&quot;
        upinfoshow();
        try {
            InsertContent(imgstr); 
         }
        catch (Error) {
            alert("插入图片错误：" + Error.description);
        }
        finally { 
        }
       /*
        var ifr = window.frames['ifr'];
        createcfm(ifr);*/
       
        //给picid_txt赋值
        var picid_txt = "#<%=picid_txt.ClientID %>";
        var picids = $(picid_txt).prop("value");
        if (picids == "" || picids == undefined)
            picids = picid;
        else
            picids += "," + picid;
        $(picid_txt).val(picids); //赋值完
        
        //以下显示信息
        var count = parseInt(document.getElementById("piccount").innerHTML);
        count++;
        document.getElementById("piccount").innerHTML = count;
        // document.getElementById("picinfo").innerHTML += '<li>图片编号: <span style="color:red">' + picid + '</span> <a href="#" onclick="InsertContent(\'' + imgstr + '\');">插入</a> <a href="#" onclick="delfun(' + picid + ');">删除</a></li>';
        var tempinfo=$("#picinfo").html();
        tempinfo += "<li>图片编号: <span style='color:red'>" + picid + "</span> <span style='color:blue;cursor:pointer;' onclick='insertpic(\"" + str + "\");'>插入</span> <a href='javascript:void(0);' onclick='delfun(" + picid + ",this);'>删除</a></li>";
        $("#picinfo").html(tempinfo);
        /*
        window.frames['ifr'].history.go(-1);
        return false;
        */
    }
    function upinfoshow() { $("#Uppic").css("display", ""); }

    function insertpic(str) {
        var imgstr = '<img src="' + str + '" alt=""  />';
        InsertContent(imgstr);
    }
    function insertpic2(picid) {
        $.ajax({
            type: "POST",
            url: "jquery/getimgstr.aspx",
            dataType: "text",
            data: { "p": "" + picid + ""}, //p传输的参数
            success: function (text) {
                if (text != "0") {
                    var imgstr = '<img src="' + text + '" alt=""  />';
                    InsertContent(imgstr);
                }
            }, error: function (html) { alert("没有权限!"); }
        });
        
    }
    
    //以下为删除图片
    function delfun(picid,obj) {
        if (confirm('确实要删除吗?')) {
            var count = parseInt($("#piccount").html());
            count--;
            var picid_txt = "#<%=picid_txt.ClientID %>";
            var picids = $(picid_txt).prop("value");
            $.ajax({
                type: "POST",
                url: "jquery/delpic.aspx",
                dataType: "html",
                data: { "p": "" + picid + "", "ps": "" + picids + "" }, //p,ps传输的参数
                success: function(html) {
                    if (html != "0") {
                        //   $("#picinfo").html(html);
                        $(obj).parent().remove();
                        $("#piccount").html(count);
                        reduceid(picid);
                    }
                }, error: function(html) { alert("没有权限!"); }
            });
        }
   }
   function reduceid(picid) {
           var picid_txt = "#<%=picid_txt.ClientID %>";
           var picids = $(picid_txt).prop("value");
           var p = picids.split(',');
           var newv = "";
           for (i = 0; i < p.length; i++) {
               if (p[i] != picid) {
                   if (newv == "")
                       newv += p[i];
                   else
                       newv += "," + p[i];
               }
           }
           $(picid_txt).val(newv);  

   }

   //修改时载入
   function showeditpic(str) {
       if (str != "") {
           upinfoshow();
           //给picid_txt赋值
           var picid_txt = "#<%=picid_txt.ClientID %>";
           $(picid_txt).val(str); //赋值完

           //以下显示信息
           var p = str.split(',');
           var newv = "";
           var picid = "";
           var picinfotemp=$("#picinfo").html();
           for (i = 0; i < p.length; i++) {
               picid = p[i];
               picinfotemp += "<li>图片编号: <span style='color:red'>" + picid + "</span>  <a href='javascript:void(0);' onclick='insertpic2(" + picid + ");'>插入</a>  <a href='javascript:void(0);' onclick='delfun(" + picid + ",this);'>删除</a></li>";               
           }
           $("#picinfo").html(picinfotemp);
           $("#piccount").html(p.length);
       }
        
   }
</script>
<tr id="Uppic" class="bg1"  style="display:none;">
  <td align="right">内容图片(<span style="color:Green;"><span id="piccount">0</span></span>)：</td>
  <td><ul id="picinfo"></ul><asp:HiddenField  ID="picid_txt" runat="server" Value="" /></td>
</tr>