<%
Option Explicit
Response.Expires = -1000
%>
<!--#INCLUDE file="constants.asp" -->
<%
Dim objConn
Dim objRecordSet
Dim strID
Dim strSQL

'catches the blogid given in the URI to this page. If not present, the id will be 0 (for errortrapping)
if request("id") = "" then
	strID = "0"
else

	strID = cstr(request("id"))
	
end if

'using the standard Microsoft ADO components to open databases. Has to be present on server (MS MDAC)
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath(LOCATION))
strSQL = "SELECT volgnr, author, date, email, homepage, comment FROM COMMENTS WHERE refernr ='" & strID & "' ORDER BY volgnr DESC"
Set objRecordSet = objConn.Execute(strSQL)
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title><% response.write TITLEPAGE %></title>
	<meta name="MSSmartTagsPreventParsing" content="TRUE">
	<style type="text/css" media="all">
		@import "comments.css";
	</style>

<!-- DAVIDS -->
<script language="JavaScript" type="text/javascript">
function commentEmoticon(code)
{
	var cache = document.formComment.comment.value;

	document.formComment.comment.value = cache + " " + code;
	document.formComment.comment.focus();
}

function commentLeftchars()
{
	var comment = event.srcElement;
	var limit = "1000";

	if (comment.value.length > limit)
	{
		comment.value = comment.value.substring(0,limit);
		left = "0";
	}
	else
	{
		left = limit - comment.value.length;
	}
	document.formComment.leftchars.value = left;
}


    </script>

<!-- END DAVIDS -->

</head>
<body topmargin="0">
<div id="content">
<div id="title">
<h1><% response.write TITLEPAGE %></h1>
</div>
<div id="comments">
<%
if cstr(request("message")) <> "" then
	response.write "<p class=""message"">" & cstr(request("message")) & "</p>"
end if

'Some explanation:
'If the homepage field contains a value, the authorname will be a link to the homepage.
'If the homepage fiels is empty, but the e-mail field is filled, the authorname will be a mailto link.
'If neither field is filled, the name is displayed as text.

if (objRecordSet.BOF And objRecordSet.EOF) then
	response.write "<p>[no comments yet]</p>"
elseif strID = 0 then
	response.write "<p>[no comments yet]</p>"
else
	Do While NOT objRecordSet.EOF 
	response.write "<p class=""commenttext"">"
	response.write objRecordSet("comment").Value & "</p>" & vbCRLF & "<p class=""smaller"">"
	if len(objRecordSet("homepage").Value) > 1 then
		response.write "<a href=""" & objRecordSet("homepage").Value & """ target=""_top"">" & objRecordSet("author").Value & "</a>"
	elseif  len(objRecordSet("email").Value) > 1 then
		response.write "<a href=""mailto:" & objRecordSet("email").Value & """>" & objRecordSet("author").Value & "</a>"
	else
		response.write objRecordSet("author").Value
	end if
	response.write " on " & FormatDateTime(objRecordSet("date").Value,1) & " at " & FormatDateTime(objRecordSet("date").Value,4) & "</p>" & vbCRLF

	objRecordSet.MoveNext
	Loop
end if

objConn.Close
Set objRecordSet = Nothing
Set objConn = Nothing

%>
</div>
<div id="newcomment">
<p align="center">
<table cellpadding="0" cellspacing="0" class="iexbar" width="326">
<tr>
<td width="15">
<img src="emoticons/grip_blue.gif" width="15" height="19"></td>
<td align="center" width="286" bgcolor="#6598CC"><b><font color="#FFFFFF"><a name="addcomment">Add Comment</a></font></font></b></td>
<td align="right" width="25">
<img src="emoticons/nochevron.gif" width="25" height="19"></td>
</tr>
<tr>
<td colspan="3">
<table cellpadding="0" cellspacing="0" class="iexbar-content" width="326">
<form action="db_action.asp" method="post" name="formComment">
<input name="newcommententrynumber" type="hidden" value="171">
<tr>
<td bgcolor="#EDEDED">
<font class="font-medium">
Name *
</font>
</td>
<td bgcolor="#EDEDED">
<input maxlength="30" name="author" size="30" type="text" value="<% = session("author") %>">
</td>
</tr>
<tr>
<td bgcolor="#EDEDED">
<font class="font-medium">
E-Mail
</font>
</td>
<td bgcolor="#EDEDED">
<input maxlength="30" name="email" size="30" type="text" value="<% = session("email") %>">
</td>
</tr>
<tr>
<td bgcolor="#EDEDED">
<font class="font-medium">
Homepage
</font>
</td>
<td bgcolor="#EDEDED">
<input type="text" name="homepage" maxlength="100" size="22" value="<% 
	if session("homepage") = "" then 
		response.write "http://"
	else 
		response.write session("homepage")
	end if %>">
</td>
</tr>
<tr>
<td bgcolor="#EDEDED">
<table cellpadding="0" cellspacing="0">
<tr>
<td align="center" colspan="3">
<font class="font-item">
Smilies:
</font>
</td>
</tr>
<tr>
<td>
<img alt=":)" onclick="commentEmoticon(':)')" src="emoticons/smile.gif" width="20" height="20"></td>
<td>
<img alt=":O" onclick="commentEmoticon(':O')" src="emoticons/shocked.gif" width="20" height="20"></td>
<td>
<img alt=":(" onclick="commentEmoticon(':(')" src="emoticons/sad.gif" width="20" height="20"></td>
</tr>
<tr>
<td>
<img alt=":D" onclick="commentEmoticon(':D')" src="emoticons/biggrin.gif" width="20" height="20"></td>
<td>
<img alt=":P" onclick="commentEmoticon(':P')" src="emoticons/tongue.gif" width="20" height="20"></td>
<td>
<img alt=";)" onclick="commentEmoticon(';)')" src="emoticons/wink.gif" width="20" height="20"></td>
</tr>
<tr>
<td>
<img alt=":angry:" onclick="commentEmoticon(':angry:')" src="emoticons/angry.gif" width="20" height="20"></td>
<td>
<img alt=":blush:" onclick="commentEmoticon(':blush:')" src="emoticons/blush.gif" width="20" height="20"></td>
<td>
<img alt=":confused:" onclick="commentEmoticon(':confused:')" src="emoticons/confused.gif" width="20" height="20"></td>
</tr>
<tr>
<td>
<img alt=":cool:" onclick="commentEmoticon(':cool:')" src="emoticons/cool.gif" width="20" height="20"></td>
<td>
<img alt=":crazy:" onclick="commentEmoticon(':crazy:')" src="emoticons/crazy.gif" width="20" height="20"></td>
<td>
<img alt=":cry:" onclick="commentEmoticon(':cry:')" src="emoticons/cry.gif" width="20" height="20"></td>
</tr>
<tr>
<td>
<img alt=":doze:" onclick="commentEmoticon(':doze:')" src="emoticons/doze.gif" width="20" height="20"></td>
<td>
<img alt=":hehe:" onclick="commentEmoticon(':hehe:')" src="emoticons/hehe.gif" width="20" height="20"></td>
<td>
<img alt=":laugh:" onclick="commentEmoticon(':laugh:')" src="emoticons/laugh.gif" width="20" height="20"></td>
</tr>
<tr>
<td>
<img alt=":plain:" onclick="commentEmoticon(':plain:')" src="emoticons/plain.gif" width="20" height="20"></td>
<td>
<img alt=":rolleyes:" onclick="commentEmoticon(':rolleyes:')" src="emoticons/rolleyes.gif" width="20" height="20"></td>
<td>
<img alt=":satisfied:" onclick="commentEmoticon(':satisfied:')" src="emoticons/satisfied.gif" width="20" height="20"></td>
</tr>
</table>
</td>
<td bgcolor="#EDEDED">
<textarea cols="25" name="comment" onchange="commentLeftchars()" onfocus="commentLeftchars()" onkeydown="commentLeftchars()" onkeyup="commentLeftchars()" rows="10" wrap="virtual"><% response.write session("comment") %></textarea>

<!-- this script checks if there are entries in the required fields -->
<script language="JavaScript" type="text/javascript">
<!--
	function CheckFields() {
		if (document.formComment.author.value.length < 1 ) {
				alert ("<% response.write ADDNAME %>");
				document.formComment.author.focus();
				return false;
				}
		if (document.formComment.comment.value.length < 1 ) {
			alert ("<% response.write ADDCOMMENT %>");
				document.formComment.comment.focus();
				return false;
			}
			else {
				return true;
			}
	}
//-->
    </script>


</td>
</tr>
<tr>
<td align="center" bgcolor="#EDEDED">
<input disabled name="leftchars" size="2" type="text" value="1000">
</td>
<td align="center" bgcolor="#EDEDED">
<p><input type="submit" name="cmdSubmit" value="Add your comment" onclick="return CheckFields();"></p>
<input type="hidden" name="id" value="<% = strID %>">
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>