<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PictureType.ascx.cs"
    Inherits="PowerEasy.Module.General.WebSite.Admin.Controls.FieldControl.PictureType" %>
<table border='0' cellpadding='0' cellspacing='1' width='100%'>
    <tr class='tdbg'>
        <td class="tdbg">
            <asp:TextBox ID="TxtImageText" runat="server"></asp:TextBox>
            <pe:ExtendedLabel ID="LblIsFromSelected" runat="server" HtmlEncode="false" Text=""></pe:ExtendedLabel>
            <pe:RequiredFieldValidator ID="ReqTxtImageText" runat="server" ControlToValidate="TxtImageText"
                SetFocusOnError="true" ErrorMessage="<%$ Res : Controls_FieldControl_PictureType_ReqTxtImageText, 必填项不能为空 %>"
                Display="Dynamic" Visible="false"></pe:RequiredFieldValidator>
            <pec:FloatingDialog ID="FloatingDialog1" runat="server" ShowType="1" Width="500"
                Height="300" Name="预览" Skin="inputbutton" Title="预览" />
            <pec:FloatingDialog ID="ImageCropperDialog" runat="server" ShowType="1" Width="580"
                Height="465" Name="裁剪" Skin="inputbutton" Title="图片裁剪" />
            <span style="color: Green">
                <%= Description %>
            </span>
        </td>
    </tr>
    <tr class='tdbg' runat="server" id="ShowUploadFiles" style="display: none;">
        <td class="tdbg" align="left">
            <pec:FloatingDialog ID="FileFloatingDialog" Visible="false" runat="server" ShowType="1"
                Width="500" Height="350" Name="从已上传文件中选择" Skin="inputbutton" Title="从已上传文件中选择" />
            <asp:DropDownList ID="DropUploadFiles" runat="server">
                <asp:ListItem Value="" Text="<%$ Res : Controls_FieldControl_PictureType_ListItem1, 不指定首页图片 %>"></asp:ListItem>
            </asp:DropDownList>
            <asp:HiddenField ID="HdnUploadFiles" runat="server" />
            <tr class='tdbg'>
                <td align="left">
                    <pe:FileUploadControl runat="server" ID="FileUploader" />
                </td>
            </tr>

        </td>
    </tr>
</table>

<script type="text/javascript">
    imgPreview('<%=m_ShowPicPath %>');
    function imgPreview(url) {
        try { eImgPreview.src = url; } catch (e) {
            setTimeout("imgPreview(' " + url + "')", 2000);

        }
    }
    function <%= m_JSPrefix %>DealwithUploadErrMessage(message) {
    alert(message);
}

function <%= m_JSPrefix %>DealwithUpload(path, size, id,thumb) {

        if (thumb && $.trim(thumb)!=='') {
             document.getElementById("<%= TxtImageText.ClientID %>").value = thumb;
        }else{
            document.getElementById("<%= TxtImageText.ClientID %>").value = path;
        }
        


    <%= m_JSPrefix %>AddItem(path);
    var isThumb = "<%= m_IsThumb %>";

    if (isThumb == "true") {
        if (path.lastIndexOf(".") > 0) {
            var temp = path.substring(0, path.lastIndexOf("."));
            var url = path;
            if (temp.lastIndexOf("_S") != temp.length - 2) {
                url = path.substring(0, path.lastIndexOf(".")) + "_S" + path.substring(path.lastIndexOf("."), path.length);
            }

            document.getElementById("<%= TxtImageText.ClientID %>").value = url;
            <%= m_JSPrefix %>AddItem(url);
        }
    }

    //系统首页图片处理  
    try {
        setTimeout("try{setpic('" + path + "')}catch(e){}", 1000);
    }
    catch (e) {
    }
}

function <%= m_JSPrefix %>DealwithUpload2(path, isThumb2) {
        document.getElementById("<%= TxtImageText.ClientID %>").value = path;


    <%= m_JSPrefix %>AddItem(path);

    if (isThumb2 == "true" || isThumb2 === true) {
        if (path.lastIndexOf(".") > 0) {
            var url = path.substring(0, path.lastIndexOf(".")) + "_S" + path.substring(path.lastIndexOf("."), path.length);
            document.getElementById("<%= TxtImageText.ClientID %>").value = url;
            <%= m_JSPrefix %>AddItem(url);
        }
    }

    //系统首页图片处理  
    try {
        setTimeout("try{setpic('" + path + "')}catch(e){}", 1000);
    }
    catch (e) {
    }
}

function <%= m_JSPrefix %>AddItem(strFileName) {
        var arrName = strFileName.split('.');
        var FileExt = arrName[1];
        var dropUploadFiles = document.getElementById("<%=this.DropUploadFiles.ClientID %>");
    var hdnUploadFiles = document.getElementById("<%=this.HdnUploadFiles.ClientID %>");
    var isAdded = false;
    for (var i = 0; i < dropUploadFiles.options.length; i++) {
        if (dropUploadFiles.options[i].value == strFileName) {
            isAdded = true;
            break;
        }
    }
    if (!isAdded) {
        dropUploadFiles.options[dropUploadFiles.length] = new Option(strFileName, strFileName);
        dropUploadFiles.selectedIndex += 1;
        PSetUrl(strFileName);
        if (hdnUploadFiles.value == '') {
            hdnUploadFiles.value = strFileName;
        } else {
            hdnUploadFiles.value = hdnUploadFiles.value + '|' + strFileName;
        }
    }
}

function <%= m_JSPrefix %>OnUploadCompleted(errorNumber, fileName) {
        switch (errorNumber) {
            case 0:	// No errors
                alert("<%= Resources.DynamicPageResources.Controls_FieldControl_PictureType_JS1 %>" + fileName + "<%= Resources.DynamicPageResources.Controls_FieldControl_PictureType_JS2 %>");
		    break;
        case 1:
            alert("<%= Resources.DynamicPageResources.Controls_FieldControl_PictureType_JS3 %>");
		    return;
        case 2:
            alert("<%= Resources.DynamicPageResources.Controls_FieldControl_PictureType_JS4 %>");
		    return;
        default:
            alert('<%= Resources.DynamicPageResources.Controls_FieldControl_PictureType_JS5 %>' + errorNumber);
		    return;
    }
}
</script>

