<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<html>
	<head runat="server">
		<title>Exemplo com Ajax</title>
	</head>
	<body>
		<form id="form1" runat="server">
			<div>
			<table style="width: 707px">
				<tr>
				<td style="width: 13px; height: 127px;">
					<asp:TreeView ID="TreeView1" runat="server" ImageSet="Arrows"
						Height="110px" NodeWrap="True" ShowLines="True">
					<Nodes>
					<asp:TreeNode Text="Produtos" Value="0" Expanded="True"
						SelectAction="None">
						<asp:TreeNode Text="Livros" Value="1"></asp:TreeNode>
						<asp:TreeNode Text="Eletr&#244;nicos" Value="2"></asp:TreeNode>
						<asp:TreeNode Text="Cal&#231;ados" Value="3"></asp:TreeNode>
							<asp:TreeNode Text="Vestu&#225;rio" Value="4"></asp:TreeNode>
						</asp:TreeNode>
					</Nodes>
					<ParentNodeStyle Font-Bold="False" />
					<HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
					<SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD"
						HorizontalPadding="0px"
						VerticalPadding="0px" />
					<NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" 
					HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
					</asp:TreeView>
				</td>
				<td style="width: 100px; height: 127px;">
					<div id="idResposta" style="text-align: right" align="right"
					nowrap="nowrap"></div>
				</td>
				</tr>
			</table>
			</div>
		</form>
		<script type="text/javascript">
			var obj;
			function AcessaPagina() {
				try {
					obj = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e) {
				try {
					obj = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(ex) {
					obj = null;
				}
				if(!obj && typeof XMLHttpRequest != "undefined") {
					obj = new XMLHttpRequest();
				}
			}
			if(obj!=null) {
				var index= new String(document.getElementById("TreeView1_SelectedNode").value)
				var param=index.substring((index.length-1),index.length)
				obj.onreadystatechange = Resposta;
				obj.open("GET","http://localhost/capitulo12/conteudo.aspx?id=" + param, true);
				obj.send(null);
			}
			return false;
			}
			function Resposta() {
				if(obj.readyState == 4) {
					if(obj.status == 200) 	{
						var saida=obj.responseText;
						document.all('idResposta').innerHTML = saida;
					}
					else {
						document.all('idResposta').innerHTML ="Ocorreu um erro ao retornar os dados.";
					}
				}
			}
		</script>
	</body>
</html>
