<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SelectUploadFiles.aspx.cs" Inherits="PowerEasy.Module.General.WebSite.Admin.Accessories.SelectUploadFiles" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>选择文件</title>
</head>
<script type="text/javascript" language="javascript">
    var cuturl = "ImageCropper.aspx?Type=select&ImgId=<%=showPicUrlID %>";
    $(document).ready(
    function () {
        var obj = parent.document.getElementById('<%=clientControlId %>');
        if (obj != null && (obj.value != NaN || obj.value != '')) {
            $("#<%=showPicUrlID %>").attr("value", obj.value);
        }
        ShowBookmarks(1);
        $("#<%=showPicUrlID %>").change(function () {
            var path = $(this).val();
            UpdateSelectPath(path);
            if (path == "") {
                $("#IfShowPic").hide();
            } else {
                if (path.match(/http:\/\/|https:\/\//gi) == null) {
                    var url = '<%=picUrl%>';
                    path = url + path;
                }
                $("#IfShowPic").attr("src", path);
                $("#IfShowPic").show();
            }
        });
    });
    function ShowBookmarks(id) {
        $("#AdminTabs >ul >li").each(
        function (i) {
            if (id == i) {
                $(this).attr("id", "current");
                $("#tab" + i).show();
            } else {
                $(this).removeAttr("id");
                $("#tab" + i).hide();
            }
            $("#Iframe1").attr("src", "");
            if (id == 3) {
                $("#Iframe1").attr("src", cuturl);
            }
            if (id == 0) {
                var path = $("#<%=showPicUrlID %>").val();
                if (path == "") {
                    $("#IfShowPic").hide();
                } else {
                    if (path.match(/http:\/\/|https:\/\//gi) == null) {
                        var url = '<%=picUrl%>';
                        if (path.indexOf("Template") < 0) {
                            url = '<%=fileServerUploadPath%>';
                        }
                        path = url + path;
                    }
                    $("#IfShowPic").attr("src", path);
                    $("#IfShowPic").show();
                }
            }
        });
    }

    function DealwithUploadErrMessage(msg) {
        alert(msg);
    }

    function DealwithImageCropper(path) {
        $("#<%=showPicUrlID %>").attr("value", path);
        UpdateSelectPath(path);
        if (path.match(/http:\/\/|https:\/\//gi) == null) {
            var url = '<%=picUrl%>';
            if (path.indexOf("Template") < 0) {
                url = '<%=fileServerUploadPath%>';
            } 
            path = url + path;
        }
        $("#IfShowPic").attr("src", path);
        ShowBookmarks(0);
    }

    function DealwithUpload(path, site, id) {
        $("#<%=showPicUrlID %>").attr("value", '<%=uploadPath%>' + path);
        UpdateSelectPath('<%=uploadPath%>' + path);
        if (path.match(/http:\/\/|https:\/\//gi) == null) {
            var url = '<%=picUrl%>';
            if (path.indexOf("Template") < 0) {
                url = '<%=fileServerUploadPath%>';
            }           
            path = url + path;
        }
        $("#IfShowPic").attr("src", path);
        ShowBookmarks(0);
    }

    function UpdateSelectPath(path) {
//        $("#<%=showPicUrlID %>").attr("value", path);
        var obj = parent.document.getElementById('<%=clientControlId %>');
        obj.value = path;
    }
</script>
<body>
    <form id="form1" runat="server">
    <div>
    <table border='0' cellpadding='0' cellspacing='0' width='100%'>
        <tr>
            <td id="AdminTabs">
                <ul>
                    <!-- CSS Tabs -->
                    <li id="current" onclick="ShowBookmarks(0)">
                     <a> <span>预览</span></a> 
                    </li>
                    <li onclick="ShowBookmarks(1)">
                       <a> <span>从已上传中选择</span></a> 
                    </li>
                    <li onclick="ShowBookmarks(2)"> 
                       <a><span>上传</span></a> 
                    </li>
                    <li onclick="ShowBookmarks(3)">    
                      <a><span>裁剪</span></a> 
                    </li>
                </ul>
            </td>
        </tr>
    </table>
    <table width="100%" border="0" cellpadding="0" cellspacing="0" id="tab0" style="display:none">
        <tr>
             <td>
             <br />
                源文件：<asp:TextBox ID="TxtShowPic" runat="server" Width="300"></asp:TextBox><br />
                预览：
                <iframe id="IfShowPic" src="" frameborder="0" style="width: 98%; height: 300px;"></iframe>
             </td>
         </tr>
    </table>
    <table width="100%" border="0" cellpadding="0" cellspacing="0" id="tab1" style="display:none">
        <tr>
             <td>
                <iframe id="uploadfile" src="ShowUploadFiles.aspx?Type=select&ThumbClientId=<%=showPicUrlID %>" frameborder="0" style="width: 98%; height: 320px;"></iframe>
             </td>
         </tr>
    </table>
    <table width="100%" border="0" cellpadding="0" cellspacing="0" id="tab2" style="display:none">
        <tr>
             <td>
                <br />
                <pe:FileUploadControl runat="server" ID="fileUploader" CustomReturnJSFunction="DealwithUpload" IsAdminManage="true" />
             </td>
         </tr>
    </table>
    <table width="100%" border="0" cellpadding="0" cellspacing="0" id="tab3" style="display:none">
        <tr>
             <td>
              <iframe id="Iframe1" name="Iframecut" src="ImageCropper.aspx?Type=select&ImgId=<%=showPicUrlID %>" frameborder="0" style="width: 98%; height: 320px;"></iframe>
             </td>
         </tr>
    </table>
    </div>
    </form>
</body>
</html>
