<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ImageBox.ascx.cs" Inherits="MTCUN.HtmlBox.ImageBox" %>



<%@ Register Src="../UserCol/Progress.ascx" TagName="Progress" TagPrefix="uc1" %>



<input id="SelectedType" type="hidden" runat="server" />
<input id="SelectedName" type="hidden" runat="server" />
<input id="SelectedDiv" type="hidden" runat="server" />
<input id="pos" type="hidden" runat="server" />

<div style="width: 600px; height: 40px;">
    <ul class="mt-listitems" style="vertical-align: middle">
        <li>
            <div style="width: 200px">
                <asp:TextBox ID="tbxNetFolder" runat="server" Width="200px" ReadOnly="True"></asp:TextBox>
            </div>
        </li>
        <li>
            <div class="btn btn-default">
                <asp:ImageButton ID="ibnUp" runat="server" ImageAlign="AbsBottom" ImageUrl="utility/folder.up.gif" OnClick="ibnUp_Click" />
            </div>
        </li>
        <li>
            <div class="btn btn-default">
                <asp:ImageButton ID="ibnNew" runat="server" ImageUrl="utility/newfolder.gif" OnClick="ibnNew_Click" />
            </div>
        </li>
        <li>
            <div class="btn btn-default">
                <asp:ImageButton ID="ibnRefurbish" runat="server" ImageUrl="utility/refurbish.gif" OnClick="ibnRefurbish_Click" />
            </div>
        </li>
        <li id="Tools" style="width: 50px"></li>
        <li>
            <div>
                <uc1:Progress ID="Progress1" runat="server" Width="50px" TextWidth="50px" />
            </div>
        </li>
    </ul>
</div>



<div id="ImageBox" style="width: 100%; height: 300px;" onclick="ClearSelected();">
    <asp:DataList ID="dlFiles" DataKeyField="Name" runat="server"
        RepeatColumns="8" RepeatDirection="Horizontal"
        OnEditCommand="dlFiles_EditCommand" OnUpdateCommand="dlFiles_UpdateCommand"
        OnSelectedIndexChanged="dlFiles_SelectedIndexChanged"
        OnDeleteCommand="dlFiles_DeleteCommand">

        <ItemTemplate>
            <asp:HiddenField ID="hfdType" Value='<%#Eval("Type")%> ' runat="server" />

            <div class="thumbnailborder">

                <%# ShowThumbnail((int)Eval("Type"), Eval("Name"),(int)Eval("Length"),Eval("Width"),Eval("Height"))%>

                <span id="spanName" class="titleHolder" onclick="onChangeName(this);event.cancelBubble=true" ondblclick="ondChangeName(this)" onmousemove="getTitle(this)">
                    <%#Eval("Name")%> 
                </span>

                <div id="divEditName" style="display: none" onclick="event.cancelBubble=true">
                    <asp:TextBox ID="tbxName" AutoPostBack="true" runat="server" Width="80px" CssClass="EditTextBox" Text='<%# System.IO.Path.GetFileNameWithoutExtension(Eval("Name").ToString())%>' OnTextChanged="tbxName_TextChanged"></asp:TextBox>
                </div>


                <div id="divDelete">
                    <asp:ImageButton ID="imgDelete" class="btn btn-default" BorderWidth="1px" runat="server" ImageUrl="utility/delete.gif" CommandName="delete" CommandArgument='<%# Eval("Type") %>' ToolTip="删除" OnClientClick="return confirm('你确定执行删除操作？');" />
                </div>
            </div>



        </ItemTemplate>
    </asp:DataList>
</div>

<script type="text/javascript">
    function GetURL(path) {

        var obj = window.opener;
        if (obj != null && obj.Edit_Object != null) {
            obj.window.frames[0].document.execCommand("InsertImage", false, path);
        }
        else {
            if (obj != null && obj.urlbox_Object != null)
            { obj.urlbox_Object.value = path; obj.ShowImage(); }
            else
            {
                parent.SelectedImage(path);
                //alert("没有发现接收对象。");
            }
        }
    }
</script>

<script type="text/javascript">
    //<![CDATA[

    var LastImageDiv = false;
    function SelectedDiv(theDiv, type, name) {
        if (LastImageDiv) {
            LastImageDiv.style.border = "solid 1px #CCCCCC";
            LastImageDiv.style.padding = "0px";

            var divs = LastImageDiv.parentNode.getElementsByTagName("div");
            for (var i = 0; i < divs.length; i++) {
                if (divs[i].id.indexOf("divDelete") == 0) {
                    divs[i].style.display = 'none';
                }
                else if (divs[i].id.indexOf("divEditName") == 0) {
                    divs[i].style.display = "none";
                }
            }

            var spans = LastImageDiv.parentNode.getElementsByTagName("span");
            for (var i = 0; i < spans.length; i++) {
                if (spans[i].id.indexOf("spanName") == 0) {
                    spans[i].style.display = "inline";
                    spans[i].style.background = "";
                    spans[i].style.padding = "0px";
                    spans[i].style.color = "#000000";
                    break;
                }
            }
        }

        LastImageDiv = theDiv;
        theDiv.style.border = "solid 2px highlight";
        theDiv.style.padding = "0px";

        var divs = theDiv.parentNode.parentNode.getElementsByTagName("div");
        for (var i = 0; i < divs.length; i++) {

            if (divs[i].id.indexOf("divDelete") == 0) {
                if (__mt_delbtnshow == 1)//判断是否是顶级
                    //divs[i].style.display = "block";
                {
                    Change(divs[i], 1);
                } else
                {
                    Change(divs[i], 0);
                }
                break;
            }
        }

        var spans = LastImageDiv.parentNode.getElementsByTagName("span");
        for (var i = 0; i < spans.length; i++) {
            if (spans[i].id.indexOf("spanName") == 0) {
                spans[i].style.background = "highlight";
                spans[i].style.padding = "0px";
                spans[i].style.color = "#ffffff";
                break;
            }
        }

    }

    function Change(theDiv, type) {
        var obj = Tools;
        if (type == 1) {
            Tools.innerHTML = theDiv.innerHTML;
        }
        else
            Tools.innerHTML = "";
    }

    function getTop(e) {
        var t = e.offsetTop
        while (e = e.offsetParent) t += e.offsetTop;
        return t;
    }

    function getLeft(e) {
        var l = e.offsetLeft
        while (e = e.offsetParent) l += e.offsetLeft;
        return l;
    }

    function onChangeName(theSpan) {
        var edit = false;
        var divs = theSpan.parentNode.getElementsByTagName("div");

        if (!LastImageDiv) {
            for (var i = 0; i < divs.length; i++) {
                if (divs[i].id.indexOf("divImage") == 0) {
                    SelectedDiv(divs[i], 0, "");
                }
            }
            return;
        }

        for (var i = 0; i < divs.length; i++) {
            if (divs[i].id.indexOf("divImage") == 0) {
                if (LastImageDiv == divs[i]) {
                    edit = true;
                }
                else {
                    SelectedDiv(divs[i], 0, "");
                }
            }
        }

        if (edit) {
            for (var i = 0; i < divs.length; i++) {
                if (divs[i].id.indexOf("divEditName") == 0) {
                    if (__mt_delbtnshow == 1)//判断是否是顶级
                    {
                        theSpan.style.display = "none";
                        divs[i].style.display = "inline";
                        var input = divs[i].getElementsByTagName("input");
                        input[0].focus();
                    }

                    break;
                }
            }
        }
    }

    function setCaret(textbox, pos) {
        var r = textbox.createTextRange();
        r.collapse(true);
        r.moveStart('character', pos);
        r.select();
    }

    function getTitle(theSpan) {
        var divs = theSpan.parentNode.getElementsByTagName("div");
        for (var i = 0; i < divs.length; i++) {
            if (divs[i].id.indexOf("divImage") == 0) {
                theSpan.title = divs[i].title;
            }
        }
    }

    function ClearSelected() {
        if (LastImageDiv) {
            LastImageDiv.style.border = "solid 1px #CCCCCC";
            LastImageDiv.style.padding = "0px";

            var divs = LastImageDiv.parentNode.getElementsByTagName("div");
            for (var i = 0; i < divs.length; i++) {
                if (divs[i].id.indexOf("divDelete") == 0) {
                    //divs[i].style.display = "none";
                    Change(divs[i], 0);
                }
                else if (divs[i].id.indexOf("divEditName") == 0) {
                    divs[i].style.display = "none";
                }
            }

            var spans = LastImageDiv.parentNode.getElementsByTagName("span");
            for (var i = 0; i < spans.length; i++) {
                if (spans[i].id.indexOf("spanName") == 0) {
                    spans[i].style.display = "inline";
                    spans[i].style.background = "";
                    spans[i].style.padding = "0px";
                    spans[i].style.color = "#000000";
                    break;
                }
            }
            LastImageDiv = false;
        }
    }

    function Reload(src) {
        alert(src);
    }
</script>


<div style="margin: 5px">
    <%# ShowThumbnail((int)Eval("Type"), Eval("Name"),(int)Eval("Length"),Eval("Width"),Eval("Height"))%>
    <ul class="mt-listitems" style="vertical-align: middle">
        <li>
            <asp:FileUpload ID="FileUpload1" CssClass="form-control" runat="server" /></li>
        <li>
            <asp:Button ID="btnUpFile" CssClass="btn btn-success" runat="server" OnClick="btnUpFile_Click" Text="上传" /></li>
    </ul>
    <br />
</div>
