<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import="java.sql.*"%>
<%	
	Connection conn = null;
	PreparedStatement stmt = null;
	ResultSet rs = null;
	try
	{
		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		conn = DriverManager.getConnection("jdbc:odbc:Presidents");		
		String sql = "SELECT PresidentID, FirstName, LastName, StartYear, EndYear, ImagePath FROM Presidents";
		stmt = conn.prepareStatement(sql);
		
		rs = stmt.executeQuery();
%>

<html>
<head>
<title>Table Rows - More info</title>
<link href="TableRowsMoreInfo.css" type="text/css" rel="stylesheet"/>
<script language="javascript" src="../../prototype.js"></script>
<script language="javascript">
function GetBio(TR,ID)
{
	var bioDiv=document.getElementById("Bio");

	new Ajax.Request("Bio.jsp",
		{
			method: "get",
			parameters: "id=" + ID,
			onComplete: _showBio
		})
	
	function _showBio(REQ) 
	{
		bioDiv.innerHTML = REQ.responseText;
	}
	
	bioDiv.style.marginTop = (ID * 50) + "px"; //position element (hack)
	bioDiv.style.visibility="visible";
}

function HideBio(TR)
{
	var bioDiv=document.getElementById("Bio");
	bioDiv.style.visibility="hidden";
	bioDiv.innerHTML="";
}

</script>
</head>

<body>
<h1>First 10 Presidents</h1>
<table id="Table" cellspacing="0">
	<thead>
		<tr>
			<th style="width:120px">President</th>
			<th style="width:60px">Years</th>
			<th style="width:50px">Image</th>
		</tr>
	</thead>
	<tbody>
	<%
	while (rs.next()) 
	{
	%>
	<tr valign="top">
		<td><%=rs.getString("FirstName") + " " + rs.getString("LastName")%></td>
		<td><%=rs.getString("StartYear")%>-<%=rs.getString("EndYear")%></td>
		<td onMouseOver="GetBio(this,<%=rs.getString("PresidentID")%>)" onMouseOut="HideBio(this)" style="cursor:pointer"><img src="Images/<%=rs.getString("ImagePath")%>"/></td>
	</tr>
	<%
	}
	%>
	</tbody>
</table>
<div id="Bio"></div>
</body>
</html>
<%
	}
	catch(Exception e)
	{
		out.write("failed: " + e.toString());
	}
	finally 
	{
		if (rs != null) rs.close();
		if (stmt != null) stmt.close();
		if (conn != null) conn.close();
	}
%>