// threaded comments script

// reply to comment
function replyToComment(commentId){
  $("#commentsForm").remove().appendTo("#replyForm"+commentId);
  $("#pr_commentParentId").val(commentId);
  if (commentId)
   $("form", "#replyForm"+commentId).submit(replyToSubmit);
  
  jQuery.each( $(".field", "#commentsForm"), function () {
    // hint values in reply-to mode
    if (commentId > 0) {
     var s = $(this).attr("replyValue");
     var inp = $("input:visible, textarea:visible", this).eq(0);
     if (!inp.val()) 
       inp.val(s);
     inp.focus(function () { if (this.value == s) this.value=''})
       .blur(function () { if (this.value == '') this.value=s});
    }
    else
     $("input, textarea", this).val("");
  })

}

// sumbit form event
function replyToSubmit() {
  $(".field", this).each(function(){
   var inp = $("input:visible, textarea:visible", this).get(0); 
   if (inp.value == $(this).attr("replyValue")) inp.value = '';
  });
}
