<%--<%@ Page Language="C#" MasterPageFile="~/bitrix/admin/AdminMasterPage.master" AutoEventWireup="true"
	CodeFile="FileManUpload.aspx.cs" Inherits="bitrix_admin_FileManUpload" Title="<%$ Loc:PageTitle %>"
	StylesheetTheme="AdminTheme" Theme="AdminTheme" EnableViewState="false"  EnableEventValidation="false" %> zg--%>
	
	<%@ Page Language="C#" MasterPageFile="~/bitrix/admin/AdminMasterPage.master" AutoEventWireup="true"
	CodeFile="FileManUpload.aspx.cs" Inherits="bitrix_admin_FileManUpload" Title="<%$ Loc:PageTitle %>"
	EnableViewState="false"  EnableEventValidation="false" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <script type="text/javascript">
		<% string uploadFileIdPrefix = "_inputFile"; %>
		function fileMan_NewFileName(ob)
		{
			var str_filename;
			var filename;
			var str_file = ob.value;
			var pref = ob.id.slice(0, -<%= uploadFileIdPrefix.Length %>);
			var num = pref.substr(pref.lastIndexOf('_')+1);
				
			str_file = str_file.replace(/\//g, '\\');
			filename = str_file.substr(str_file.lastIndexOf('\\')+1);
			document.getElementById(pref + '_fileName').value = filename;
			var counter = document.getElementById('<%= fileCount.ClientID %>');
			if(counter.value==num)
			{
				num++;
				var tbl = document.getElementById('fileManUpload_uploadsTable');
				var cnt = tbl.rows.length;
				var oRow = tbl.insertRow(cnt);
				var oCell = oRow.insertCell(0);
				oCell.innerHTML = '<input id="<%= uploadItems.ClientID %>_item_'+num+'_fileName" name="<%= uploadItems.UniqueID %>$item_'+num+'$fileName" type="text" maxlength="255" size="30" value="">';
				var oCell = oRow.insertCell(1);
				oCell.innerHTML = '<input id="<%= uploadItems.ClientID %>_item_'+num+'_inputFile" name="<%= uploadItems.UniqueID %>$item_'+num+'$inputFile" type="file" maxlength="255" size="50" value="" onChange="fileMan_NewFileName(this);">';
				counter.value = num;
			}
		}
		function fileMan_GoBack()
		{
			window.location.href = '<%= Bitrix.Services.Js.BXJSUtility.Encode(BackUrl) %>';
			return false;
		}
		function fileMan_ConfirmOverwrite(sender, args)
		{
			args.IsValid = true;
			
			var counter = document.getElementById('<%= fileCount.ClientID %>');
			var files = [];
			var names = [];
			for(var i = 1; i <= counter.value; i++)
			{
				var prefix = '<%= uploadItems.ClientID %>_item_' + i;
				var file = document.getElementById(prefix + '_inputFile').value;
				if (file == '')
					continue;
				
				files.push(file);
				names.push(document.getElementById(prefix + '_fileName').value);
			}
			
			if (files.length == 0)
				return;
				
			var request = null;
		    if(window.XMLHttpRequest)
		    {
			    try {request = new XMLHttpRequest();} catch(e){}
		    }
            else if(window.ActiveXObject)
            {
                try {request = new ActiveXObject("Microsoft.XMLHTTP");} catch(e){}
                if(!request)
            	    try {request = new ActiveXObject("Msxml2.XMLHTTP");} catch (e){}
            }
    		
    		var postData = '';
    		for(var i = 0; i < files.length; i++)
    		{
    			if (i != 0)
    				postData += '&';
    			postData += 'file=' + encodeURIComponent(files[i]) + '&name=' + encodeURIComponent(names[i]);
    		}
    		
    		
    		var isSuccessful = true;
            try
            { 
                request.open(
					"POST", 
					'<%= JSEncode(VirtualPathUtility.ToAbsolute("~/bitrix/admin/FileManUpload.aspx")) %>?path=<%= JSEncode(UrlEncode(curPath)) %>&check=',
					false
				);
				
				request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				request.setRequestHeader("Content-length", postData.length);
				request.setRequestHeader("Connection", "close");
				
                request.send(postData); 
            } 
            catch(e)
            {
                isSuccessful = false;       
            }
    	    isSuccessful &= (request.status == 200);
    	    
	        if(!isSuccessful)
				return;
			
			var filesExist = eval('(' + request.responseText + ')');
			
			if (filesExist == null || !(filesExist instanceof Array) || filesExist.length == 0)
				return;
				
			var filesList = '';
			for(var i = 0; i < filesExist.length; i++)
			{
				if (i != 0)
					filesList += ', ';
				filesList += filesExist[i];
			}
			
			var overwrite = args.IsValid = confirm('<%= JSEncode(string.Format(GetMessageRaw("Message.OverwriteFiles"), curPath)) %>'.replace(/#FILES#/g, filesList));
			if (overwrite)
				document.getElementById('<%= Overwrite.ClientID %>').value = "Y";
		}
	</script>
	
	<% ButtonBack.Href = BackUrl;%>
    <bx:BXContextMenuToolbar id="BXContextMenuToolbar1" runat="server">
        <Items>
			<bx:BXCmImageButton runat="server" ID="ButtonBack" CssClass="context-button icon btn_folder_up" CommandName="back"
				Text="<%$ Loc:ActionText.GoBack %>" Title="<%$ Loc:ActionTitle.GoBack %>"
				/>
		</Items>
    </bx:BXContextMenuToolbar>
	<bx:BXValidationSummary ID="errorMessage" runat="server" CssClass="errorSummary" HeaderText="<%$ Loc:Kernel.Error %>" />
	<bx:BXMessage ID="successMessage" runat="server" Content="<%$ Loc:Message.Success %>"
		CssClass="ok" IconClass="ok" Title="<%$ Loc:Kernel.Information %>" Visible="False"
		Width="438px" />
	<bx:BXTabControl ID="mainTabControl" runat="server" OnCommand="mainTabControl_Command" ValidationGroup="Upload" >
		<bx:BXTabControlTab runat="server" Selected="True" Text="<%$ Loc:TabText.Upload %>" Title="<%$ Loc:TabTitle.Upload %>">
		    <asp:HiddenField runat="server" ID="fileCount" />
		    <asp:HiddenField runat="server" ID="Overwrite" />
		    <asp:CustomValidator runat="Server" ID="ConfirmOverwrite" Display="None" ClientValidationFunction="fileMan_ConfirmOverwrite" ValidationGroup="Upload" />
			<table width="100%" cellspacing="0" cellpadding="0" border="0" class="edit-table">
				<tr>
					<td>
						<asp:Repeater ID="uploadItems" runat="server" EnableViewState="False" OnItemCreated="uploadItems_ItemCreated">
							<HeaderTemplate>
							<table id="fileManUpload_uploadsTable" cellspacing="0" cellpadding="0" border="0" class="internal">
					        <tr class="heading">
						        <td valign="middle" align="center"><%= GetMessage("Column.Filename") %></td>
						        <td valign="top" align="center"><%= GetMessage("Column.File") %></td>
					        </tr>
							</HeaderTemplate>
							<ItemTemplate>
								<tr>
									<td>
										<asp:TextBox ID="fileName" runat="server" Text="" MaxLength="255" size="30" />
									</td>
									<td>
										<asp:FileUpload ID="inputFile" runat="server" size="50" maxlength="255" />
									</td>
								</tr>
							</ItemTemplate>
							<FooterTemplate></table></FooterTemplate>
						</asp:Repeater>
					</td>
				</tr>
			</table>
		</bx:BXTabControlTab>
	</bx:BXTabControl>
</asp:Content>
