<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UploadPage.aspx.cs" EnableEventValidation="False" Inherits="DocumentRouter.UploadPage" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI" tagprefix="asp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
		<title>Tarvos Document Router</title>
		<link href="Data/DocumentRouter.css" type="text/css" rel="stylesheet" />
		<script src="Scripts/Tools.js" type="text/javascript"></script>
		<script src="Scripts/FieldUpdate.js" type="text/javascript"></script>
		<script language="javascript" type="text/javascript">
<!--

function ShowWait()
{
	try
	{
		document.body.style.cursor = 'wait';
		document.getElementById('waitImg').style.display = "";
	}
	catch(e)
	{
	}
}

function HideWait()
{
	try
	{
		document.body.style.cursor = 'default';
		document.getElementById('waitImg').style.display = "none";
	}
	catch(e)
	{
	}
}

// Redirect to AlchemyWeb logout page, so license is released
function HandleOnClose()
{
	try
	{
		if (event.clientY < 0)
		{
			if(sAlchemyLogout != '')
			{
				self.location.href = sAlchemyLogout;
			}
		}
	}
	catch(e)
	{
	}
}

var bSaveClicked = false;

function SubmitClick()
{
	try
	{
		if(bSaveClicked == false)
		{
			// Other button than save is clicked, so clear selected file
			//document.getElementById('FileUpload1').value = '';
			var browse=document.getElementById('FileUpload1');
			var newbrowse= browse.cloneNode(false);
			browse.parentNode.replaceChild(newbrowse, browse);
		}
		else
		{
		}
	}
	catch(e)
	{
		alert('SubmitClick: ' + e.description);
	}
}

function SetError(sError)
{
	try
	{
//		var objError = document.getElementById('lblError');
//		objError.Value = sError;
//		objError.Visible = true;
	}
	catch(e)
	{
		alert(e.description);
	}
}

function DoUpload(sDatabase, sDBPath, sProfiles, iframeWindow)
{
	try
	{
		var objDatabase = document.getElementById('DatabaseHidden');
		var objDBPath = document.getElementById('DBPathIDHidden');
		var objProfiles = document.getElementById('ProfilesHidden');

		objDatabase.value = sDatabase;
		objDBPath.value = sDBPath;
		objProfiles.value = sProfiles;

		bSaveClicked = false;

		ResizeFrame(iframeWindow);

		if((sDatabase.length > 0) && (sDBPath.length > 0) && (sProfiles.length > 0))
		{
			ShowWait();
			// Check if files is selected
			var fileInput = document.getElementById('FileUpload1');

			if (fileInput && fileInput.value && fileInput.value.length > 0)
			{
				bSaveClicked = true;
				form1.submit();
			}
			else
			{
				alert("Selecteer een bestand AUB");
				HideWait();
			}
		}
	}
	catch(e)
	{
		alert("Error: " + e.description);
		HideWait();
	}
}

function ResizeFrame(iframeWindow)
{
	try
	{
		if (iframeWindow.document.height)
		{
			var iframeElement = document.getElementById ("UploadProfile");
			iframeElement.style.height = iframeWindow.document.height + 'px';
			//iframeElement.style.width = iframeWindow.document.width + 'px';
		}
		else if (document.all)
		{
			var iframeElement = document.all["UploadProfile"];
			if (iframeWindow.document.compatMode && iframeWindow.document.compatMode != 'BackCompat')
			{
				iframeElement.style.height = iframeWindow.document.documentElement.scrollHeight + 'px';
				//iframeElement.style.width = iframeWindow.document.documentElement.scrollWidth + 5 + 'px';
			}
			else
			{
				iframeElement.style.height = document.body.clientHeight - 311;
				iframeElement.style.height = iframeWindow.document.body.scrollHeight + 'px';
				//iframeElement.style.width = iframeWindow.document.body.scrollWidth + 5 + 'px';
			}
		}
	}
	catch(e)
	{
	}
}

//-->
	</script>
</head>
<body onmouseover="javascript:window.status='Tarvos DocumentRouter'; return true;" onresize="javascript:ResizeTables();"
		onbeforeunload="javascript:HandleOnClose();" topmargin="0" onload="javascript:RefreshCombos(); javascript:HideWait();">
    <form id="form1" runat="server">
			<asp:ScriptManager ID="ScriptManager1" runat="server">
			</asp:ScriptManager>
			<table class="MainTable" id="tblMain" cellspacing="0" cellpadding="0" align="center">
				<tr class="Header" valign="middle">
					<td><asp:image id="Image1" runat="server" ImageUrl="~/Images/logo.png"></asp:image></td>
					<td><asp:label id="lblHeader" runat="server" ForeColor="White">Tarvos Document Router</asp:label></td>
					<td></td>
				</tr>
				<tr>
					<td style="HEIGHT: 10px" align="right" background="Images/menuback.png"
						bgColor="white" colspan="4"></td>
				</tr>
				<tr>
					<td bgColor="white" colspan="4"><asp:label id="lblError" runat="server" ForeColor="Red" Visible="False" Font-Names="Verdana"
							Font-Size="Medium">Label</asp:label></td>
				</tr>
				<tr>
					<td class="Tab"><asp:button id="btnTabReport" runat="server" Text="Selectie" CausesValidation="False" CssClass="TabButton" onclick="btnTabLeft_Click"></asp:button><asp:button id="btnTabSearch" runat="server" Text="Zoeken" CausesValidation="False" CssClass="TabButton" onclick="btnTabLeft_Click"></asp:button><asp:button id="btnTabAdd" runat="server" Text="Toevoegen" CausesValidation="False" CssClass="TabButton" onclick="btnTabLeft_Click"></asp:button></td>
					<td class="Tab">
						<p><asp:imagebutton id="btnSettings" runat="server" ImageUrl="~/Images/settings.png" CssClass="ImgButton" ToolTip="Instellingen" CausesValidation="False"></asp:imagebutton><asp:imagebutton id="btnLogOut" runat="server" ImageUrl="~/Images/exit.png" CssClass="ImgButton" ToolTip="Afsluiten" CausesValidation="False"></asp:imagebutton>&nbsp;&nbsp;<asp:Image id="waitImg" runat="server" ImageUrl="~/Images/icon_wait.gif"></asp:Image></p>
					</td>
					<td class="Tab" align="left">&nbsp;</td>
				</tr>
				<tr>
					<td class="ListColumn">&nbsp;</td>
					<td class="DocumentColumn">
						<table class="DocTable" id="tblDoc" height="100%" cellspacing="0" cellpadding="0" width="100%" style="border: 1px solid;">
							<tr valign="top" height="100%">
								<td>
									<div id="subFrame" runat="server"><telerik:RadProgressManager ID="RadProgressManager1" runat="server" OnClientSubmitting="SubmitClick" />
										<br />
										<br /><asp:Label ID="Label1" runat="server"
											CssClass="LabelText" Text="Selecteer het bestand dat u wilt opslaan in de database:" Width="99%"></asp:Label><br />
										<asp:FileUpload ID="FileUpload1" runat="server" Width="99%" CssClass="LabelText" />
										<br />
										<br />
										<telerik:RadProgressArea ID="RadProgressArea1" runat="server" Skin="Default" 
											CssClass="LabelText">
											<Localization Uploaded="Uploaded"></Localization>
										</telerik:RadProgressArea>
										<br />
										<br />
										<asp:HiddenField ID="DatabaseHidden" runat="server" Value="" />
										<asp:HiddenField ID="DBPathIDHidden" runat="server" Value="" />
										<asp:HiddenField ID="ProfilesHidden" runat="server" Value="" />
										<asp:Label ID="lblUploadedFiles" runat="server" CssClass="LabelText" Font-Bold="False"
											Text="Toegevoegde bestanden:" Width="99%"></asp:Label>
										<asp:TextBox ID="txtUploadedFiles" runat="server" Height="60px" ReadOnly="True" TextMode="MultiLine"
											Width="99%" CssClass="LabelText"></asp:TextBox>
									</div>
								</td>
							</tr>
						</table>
					</td>
					<td class="RightColumn">
						<iframe id="UploadProfile" class="RightColumn" width="240px" scrolling="auto" src="UploadProfile.aspx" frameborder="0" runat="server"></iframe>
					</td>
				</tr>
			</table>
    </form>
</body>
</html>
