<?php 
/* Don't remove these lines. */

function popuplinksbetter($text) {
	// Comment text in popup windows should be filtered through this.
	// Right now it's a moderately dumb function, ideally it would detect whether
	// a target or rel attribute was already there and adjust its actions accordingly.
	$text = preg_replace('/<a (.+?)>/i', "<a $1 target='_blank'>", $text);
	$text = preg_replace('/<a (.*?)rel=\'(.+?)\'(.*?)>/i', "<a $1rel='$2 external'$3><!--popuplinksbetter was here-->", $text);
	$text = preg_replace('/<a (.*?)rel="(.+?)"(.*?)>/i', "<a $1rel=\"$2 external\"$3><!--popuplinksbetter was here-->", $text);
	return $text;
}


add_filter('comment_text', 'popuplinksbetter');
foreach ($posts as $post) { start_wp();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
     <title><?php echo get_settings('blogname'); ?> - Comments on <?php the_title(); ?></title>

<meta name="generator" content="WordPress <?php bloginfo('version'); ?>" /> <!-- leave this for stats -->

	<meta name="robots" content="noindex" />
	<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_settings('blog_charset'); ?>" />
	<style type="text/css">@import url(<?php bloginfo('stylesheet_url'); ?>);</style>

<?php if (class_exists("canary")) { canary::wp_head(); } ?>
<?php if (function_exists('insert_fancytooltips_header_code')) { insert_fancytooltips_header_code(); } ?>
<?php if (function_exists('lmbbox_comment_quicktags_head')) { lmbbox_comment_quicktags_head(); } ?>

</head>
<body id="commentspopup" class="themed RevvedUp">

<h3 id="comments"><?php comments_number('No Responses', 'One Response', '% Responses' );?> to <a href="<?php the_permalink(); ?>" target="_blank"><?php the_title(); ?></a></h3>

<p>You can subscribe to the <a href="<?php echo get_settings('siteurl'); ?>/wp-commentsrss2.php?p=<?php echo $post->ID; ?>"><abbr title="Really Simple Syndication">RSS</abbr> feed for comments on this post.</a><?php if ('open' == $post->ping_status) { ?>    You can also reply to this post directly in your weblog, <a href="<?php trackback_url(); ?>">and take advantage of the TrackBack URI</a> to record your reply in this post.<?php } ?></p>

<?php
// this line is WordPress' motor, do not delete it.
$comment_author = (isset($_COOKIE['comment_author_' . COOKIEHASH])) ? trim($_COOKIE['comment_author_'. COOKIEHASH]) : '';
$comment_author_email = (isset($_COOKIE['comment_author_email_'. COOKIEHASH])) ? trim($_COOKIE['comment_author_email_'. COOKIEHASH]) : '';
$comment_author_url = (isset($_COOKIE['comment_author_url_'. COOKIEHASH])) ? trim($_COOKIE['comment_author_url_'. COOKIEHASH]) : '';
$comments = get_approved_comments($id);
$post = get_post($id);
if (!empty($post->post_password) && $_COOKIE['wp-postpass_'. COOKIEHASH] != $post->post_password) {  // and it doesn't match the cookie
	echo(get_the_password_form());
} else { ?>

<?php $oddcomment = 'alt'; if ($comments) { ?>

	<ol class="commentlist" id ="all_comments">
	<?php foreach ($comments as $comment) { ?>
		<li class="<?php echo $oddcomment; ?>" id="comment-<?php comment_ID() ?>">

		<?php if (function_exists('gravatar')) { 
		if ( $comment->comment_author_email || $comment->comment_author_url ) {
		if ('' != get_comment_author_url()) {
			// the commenter supplied a website URL
			echo "<a href='$comment->comment_author_url' title='Visit $comment->comment_author'>";
		} else { 
			// the commenter did not supply a website, so link to gravatars.com
			echo "<a href='http://www.gravatar.com' title='Create your own gravatar at gravatar.com!'>";
		}
		echo "<img src='";
		if ('' == $comment->comment_type) {
			// this is a regular comment, so use the commenter's email address
			echo gravatar($comment->comment_author_email);
		} elseif ( ('trackback' == $comment->comment_type) || ('pingback' == $comment->comment_type) ) {
			// this is a pingback or trackback, so use the commenter's website URL
			echo gravatar($comment->comment_author_url);
		}
		echo "' alt='' class='gravatar' /></a>";
		}
		} ?>


		<cite><?php comment_author_link() ?></cite> says:
		<?php if ($comment->comment_approved == '0') : ?>
		<em>Your comment is awaiting moderation.</em>
		<?php endif; ?>
		<br />

		<small class="commentmetadata"><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a> <?php edit_comment_link('Edit this comment','',''); ?></small>

		<?php comment_text() ?>

		</li>

	<?php /* Changes every other comment to a different class */	
		if ('alt' == $oddcomment) $oddcomment = '';
		else $oddcomment = 'alt';
	?>

	<?php } // end for each comment ?>

	</ol>

<?php } else { // this is displayed if there are no comments so far ?>

	<ol class="commentlist" id ="all_comments">
		<li class="stub">No comments posted yet</li>
	</ol>

<?php } ?>



<?php if ('open' == $post->comment_status) { ?>

	<h3 id="respond">Leave a comment</h3>

	<?php if ( get_option('comment_registration') && !$user_ID ) : ?>

		<p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php the_permalink(); ?>">logged in</a> to post a comment.</p>

	<?php else : ?>

		<p>Line and paragraph breaks automatic, e-mail address never displayed, <acronym title="Hypertext Markup Language">HTML</acronym> allowed: <code><?php echo allowed_tags(); ?></code></p>
		
		<form action="<?php echo get_settings('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">

		<?php if ( $user_ID ) : ?>
		
			<p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="Log out of this account">Logout &raquo;</a></p>
		
		<?php else : ?>

			<p>
			<input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="28" tabindex="1" />
			<label for="author">Name <?php if ($req) echo "(required)"; ?></label>
			</p>
			
			<p>
			<input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="28" tabindex="2" />
			<label for="email">Mail (will not be published) <?php if ($req) echo "(required)"; ?></label></p>
			
			<p>
			<input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" />
			<label for="url">Website</label>
			</p>
		
		<?php endif; ?>

		<p>
		<label for="comment" style="display: none">Your Comment</label>
		<?php if (function_exists('lmbbox_comment_quicktags_display')) { lmbbox_comment_quicktags_display(); } ?>
		<textarea <?php if (strstr($_SERVER["HTTP_USER_AGENT"],"Wget") === false) { ?> name="comment" <?php } else { ?> <?php } ?> id="comment" cols="70" rows="10" tabindex="4"></textarea>
		</p>
	
		<p>
		<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
		<input type="hidden" name="redirect_to" value="<?php echo wp_specialchars($_SERVER["REQUEST_URI"]); ?>" />
		<input name="submit" type="submit" tabindex="5" value="Post my comment" />
		</p>
		<?php do_action('comment_form', $post->ID); ?>

		</form>

	<?php endif; ?>

<?php } else { // comments are closed ?>

	<p>Comments are closed.</p>

<?php }
} // end password check
?>

<div style="float: right;"><strong><a href="javascript:window.close()">Close this window.</a></strong></div>

<?php // if you delete this the sky will fall on your head
}
?>

<!-- // this is just the end of the motor - don't touch that line either :) -->
<?php //} ?> 
<?php if (class_exists("canary")) { canary::wp_footer(); } ?>
<p class="credit"><?php timer_stop(1); ?> <cite>Powered by <a href="http://wordpress.org" title="Powered by WordPress, state-of-the-art semantic personal publishing platform"><strong>Wordpress</strong></a></cite></p>
<?php // Seen at http://www.mijnkopthee.nl/log2/archive/2003/05/28/esc(18) ?>
<script type="text/javascript">
<!--
document.onkeypress = function esc(e) {	
	if(typeof(e) == "undefined") { e=event; }
	if (e.keyCode == 27) { self.close(); }
}
// -->
</script>
</body>
</html>
