Index: extensions/reply_to/reply_to.inc.php
===================================================================
--- extensions/reply_to/reply_to.inc.php	(revision 21327)
+++ extensions/reply_to/reply_to.inc.php	(revision 26677)
@@ -1,4 +1,4 @@
 <?php 
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+defined('REPLYTO_PATH') or die('Hacking attempt!');
 
 define('REPLYTO_REGEX', '#\[reply=([0-9]+)\]([^\[\]]*)\[/reply\]#i');
@@ -11,10 +11,9 @@
   global $pwg_loaded_plugins, $template, $page, $conf, $lang;
   $template->assign('REPLYTO_PATH', REPLYTO_PATH);
-  $location = null;
   
   // comment form has different id
   if (
-    (isset($_GET['action']) AND $_GET['action'] == 'edit_comment') OR 
-    (isset($page['body_id']) AND $page['body_id'] == 'theCommentsPage')
+    (isset($_GET['action']) and $_GET['action'] == 'edit_comment') or 
+    (isset($page['body_id']) and $page['body_id'] == 'theCommentsPage')
     ) 
   {
@@ -29,8 +28,11 @@
   if (script_basename() == 'comments') 
   {
-    if ( !is_a_guest() OR $conf['comments_forall'] )
-    {
-      $comments = &$template->get_template_vars('comments');
-      if (!count($comments)) return;
+    if (!is_a_guest() or $conf['comments_forall'])
+    {
+      $comments = $template->get_template_vars('comments');
+      if (!count($comments))
+      {
+        return;
+      }
       
       // generates urls to picture or albums with necessary url params
@@ -46,4 +48,6 @@
       }
       
+      var_dump($replyto_links);
+      
       $template->assign('replyto_links', $replyto_links);
       $template->set_prefilter('comments', 'replyto_add_link_comments_prefilter');
@@ -53,8 +57,7 @@
   else if (script_basename() == 'picture') 
   {
-    $location = 'picture';
     add_event_handler('user_comment_insertion', 'replyto_parse_picture_mail');
     
-    if ( !is_a_guest() OR $conf['comments_forall'] )
+    if (!is_a_guest() or $conf['comments_forall'])
     {
       $template->set_prefilter('picture', 'replyto_add_link_prefilter');
@@ -62,15 +65,13 @@
   } 
   /* ALBUM page */
-  else if 
-    (
-      script_basename() == 'index' AND isset($page['section']) AND
-      isset($pwg_loaded_plugins['Comments_on_Albums']) AND 
-      $page['section'] == 'categories' AND isset($page['category'])
+  else if (
+      script_basename() == 'index' and isset($page['section']) and
+      isset($pwg_loaded_plugins['Comments_on_Albums']) and 
+      $page['section'] == 'categories' and isset($page['category'])
     )
   {
-    $location = 'album';
     add_event_handler('user_comment_insertion', 'replyto_parse_album_mail');
     
-    if ( !is_a_guest() OR $conf['comments_forall'] )
+    if (!is_a_guest() or $conf['comments_forall'])
     {
       $template->set_prefilter('comments_on_albums', 'replyto_add_link_prefilter');
@@ -80,25 +81,9 @@
 
   /* we come from comments.php page */
-  if ( !empty($_GET['rt']) and !empty($_GET['rta']) )
-  {
-    if ($location == 'picture')
-    {
-      $template->set_prefilter('picture', 'replyto_fillform_prefilter');
-    }
-    else
-    {
-      $template->set_prefilter('comments_on_albums', 'replyto_fillform_prefilter');
-    }    
-  }
-}
-
-/**
- * add reply tag from values given in url
- */
-function replyto_fillform_prefilter($content, &$smarty)
-{
-  $search = '<ul class="commentsList">';
-  $replace = '{footer_script require=\'insertAtCaret\'}replyTo("'.$_GET['rt'].'", "'.$_GET['rta'].'");{/footer_script}'.$search;
-  return str_replace($search, $replace, $content);
+  if (!empty($_GET['rt']) and !empty($_GET['rta']))
+  {
+    $template->func_combine_script(array('id'=>'insertAtCaret', 'path'=>REPLYTO_PATH.'insertAtCaret.js'));
+    $template->block_footer_script(array('require'=>'insertAtCaret'), 'replyTo("'.$_GET['rt'].'", "'.$_GET['rta'].'");');
+  }
 }
 
@@ -106,31 +91,27 @@
  * reply buttons on comments.php page
  */
-function replyto_add_link_comments_prefilter($content, &$smarty)
+function replyto_add_link_comments_prefilter($content)
 { 
   // style
-  $search[0] = '<ul class="commentsList">';
-  $replace[0] = '
-{html_head}
-<style type="text/css">
-  .replyTo {ldelim}
-    display:none;
-    background:url({$ROOT_URL}{$REPLYTO_PATH}reply.png) left top no-repeat;
-    height:16px;
-    margin-left:20px;
-    padding-left:20px;
-  }
-  li.commentElement:hover .replyTo {ldelim}
-    display:inline;
-  }
-  .replyTo:hover {ldelim}
-    background-position:left -16px;
-  }
-</style>
-{/html_head}'
-.$search[0];
+  $content.= '
+{html_style}
+.replyTo {
+  display:none;
+  background:url({$ROOT_URL}{$REPLYTO_PATH}reply.png) left top no-repeat;
+  height:16px;
+  margin-left:20px;
+  padding-left:20px;
+}
+li.commentElement:hover .replyTo {
+  display:inline;
+}
+.replyTo:hover {
+  background-position:left -16px;
+}
+{/html_style}';
 
   // button
-  $search[1] = '<span class="commentDate">{$comment.DATE}</span>';
-  $replace[1] = $search[1].'<a href="{$replyto_links[$comment.ID]}" class="replyTo">{\'Reply\'|@translate}</a>';
+  $search = '<span class="commentDate">{$comment.DATE}</span>';
+  $replace = $search.'<a href="{$replyto_links[$comment.ID]}" class="replyTo">{\'Reply\'|@translate}</a>';
   
   return str_replace($search, $replace, $content);
@@ -143,32 +124,28 @@
 {
   // script & style
-  $search[0] = '<ul class="commentsList">';
-  $replace[0] = '
-{combine_script id=\'insertAtCaret\' require=\'jquery\' path=$REPLYTO_PATH|@cat:\'insertAtCaret.js\'}
+  $content.= '
+{combine_script id=\'insertAtCaret\' require=\'jquery\' path=$REPLYTO_PATH|cat:\'insertAtCaret.js\'}
 
 {footer_script require=\'insertAtCaret\'}
-function replyTo(commentID, author) {ldelim}
-  jQuery("#{$replyto_form_name} textarea").insertAtCaret("[reply=" + commentID + "]" + author + "[/reply] ");
+function replyTo(commentID, author) {
+  jQuery("#{$replyto_form_name} textarea").insertAtCaret("[reply=" + commentID + "]" + author + "[/reply] ").focus();
 }
 {/footer_script}
 
-{html_head}
-<style type="text/css">
-  .replyTo {ldelim}
-    display:none;
-    background:url({$ROOT_URL}{$REPLYTO_PATH}reply.png) left top no-repeat;
-    height:16px;
-    margin-left:20px;
-    padding-left:20px;
-  }
-  li.commentElement:hover .replyTo {ldelim}
-    display:inline;
-  }
-  .replyTo:hover {ldelim}
-    background-position:left -16px;
-  }
-</style>
-{/html_head}'
-.$search[0];
+{html_style}
+.replyTo {
+  display:none;
+  background:url({$ROOT_URL}{$REPLYTO_PATH}reply.png) left top no-repeat;
+  height:16px;
+  margin-left:20px;
+  padding-left:20px;
+}
+li.commentElement:hover .replyTo {
+  display:inline;
+}
+.replyTo:hover {
+  background-position:left -16px;
+}
+{/html_style}';
 
   // button
@@ -188,5 +165,5 @@
 
 /**
- * Replace BBcode tag by a link with absolute url
+ * Replace reply tag by a link with absolute url
  */
 function replyto_parse($comment, $in_album = false)
@@ -300,4 +277,2 @@
   return $comment;
 }
-
-?>
