function commentOnArticle(articlecomment_id){
  replyTo(articlecomment_id);
}
function replyTo(articlecomment_id){
  var button=null;
  if (articlecomment_id>0){
    document.getElementById("articlecomment_parent_id").value=articlecomment_id;
    button=document.getElementById("articlecomment_"+articlecomment_id);
  }else{
    document.getElementById("articlecomment_parent_id").value=0;
    button=document.getElementById("articlecomment_button");
  }
  tinyMCE.execCommand('mceRemoveControl', false, "articlecomment_text");
  var form_div=document.getElementById("add_articlecomment");
  button.parentNode.insertBefore(form_div,button.nextSibling);
  form_div.style.display="block";
  tinyMCE.execCommand('mceAddControl', false, "articlecomment_text");
}
function rateArticleComment(articlecomment_id, rating){
  new HttpRequest().start("/ratearticlecomment.html?articlecomment_id="+articlecomment_id+"&rating="+rating+"&rnd="+encodeURIComponent(Date()), function(responseText){
                            var response=eval('('+ responseText +')');
                            var rating_span=document.getElementById("articlecomment_num_ratings_"+articlecomment_id);
                            rating_span.innerHTML=response.num_ratings;
                            rating_span.className+=" rosette";
                            var rating_prompt=document.getElementById("articlecomment_num_ratings_prompt_"+articlecomment_id);
                            rating_prompt.innerHTML="Recommended";
                          });
}
function toggleComments(comment_ids){
  for(var i=0;i<comment_ids.length;i++){
    var comment_id=comment_ids[i];
    var comment=document.getElementById("articlecomment_"+comment_id);
    if(comment.style.display=="block")
      comment.style.display="none";
    else
      comment.style.display="block";
  }
}
function expandAllComments(comment_ids){
  for(var i=0;i<comment_ids.length;i++){
    var comment_id=comment_ids[i];
    document.getElementById("articlecomment_"+comment_id).style.display="block";
  }
}
function collapseAllComments(comment_ids){
  for(var i=0;i<comment_ids.length;i++){
    var comment_id=comment_ids[i];
    document.getElementById("articlecomment_"+comment_id).style.display="none";
  }
}
function checkCommentForm(){
  var okay=true;
  var articlecomment_name=document.getElementById("articlecomment_name");
  var articlecomment_email=document.getElementById("articlecomment_email");
  var captcha_text=document.getElementById("captcha_text");
  if (articlecomment_name.value.length==0){
    okay=false;
    alert("Please provide your name");
    articlecomment_name.focus();
  }else if (articlecomment_email.value.length==0){
    okay=false;
    alert("Please provide your email address");
    articlecomment_email.focus();
  }else if (captcha_text.value.length==0){
    alert("Please type the text in the box on the left");
    captcha_text.focus();
  }else{
    var captcha_text_value=document.getElementById("captcha_text").value;
    new HttpRequest().start("/get_captcha.html?rnd="+encodeURIComponent(Date()), function(responseText){
			      responseText=trim(responseText);
                              if (captcha_text_value==responseText){
                                document.getElementById("articlecomment_form").submit();
                              }else{
                                alert("The text in the box does not match, please correct it.");
                                captcha_text.focus();
                              }
                            });
  }
  return false;
}
