function get_comment_nbs ()
  { var spans= document.getElementsByName( "cnb");
    for ( var i=0; i< spans.length; i++)
      { var span= spans[i]; comment_nb( span, span.id) }
  }

function comment_nb ( span, id)
  { var url="/cgi-bin/comment?f=nb&amp;id=" + id;
    get_request(url, span, id)
  }

function get_request(url, elt, id)
  { var xmlhttp
    // code for Mozilla, etc.
    if (window.XMLHttpRequest)
      { xmlhttp=new XMLHttpRequest()
        xmlhttp.onreadystatechange= function() { set_span_content( xmlhttp, elt, id) }
        xmlhttp.open("GET",url,true)
        xmlhttp.send(null)
      }
    // code for IE
    else if (window.ActiveXObject)
      { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
        if (xmlhttp)
          { xmlhttp.onreadystatechange= function() { set_span_content( xmlhttp, elt, id) }
            xmlhttp.open("GET",url,true)
            xmlhttp.send()
          }
      }
  }

function set_span_content( xmlhttp, elt, id )
  { // if xmlhttp shows "loaded"
    if (xmlhttp.readyState==4)
      { // if "OK"
        if (xmlhttp.status==200)
          { var nb= xmlhttp.responseText;
            if( nb == 0)
              { elt.innerHTML= "[no comments]";    }
            else if( nb == 1)
              { elt.innerHTML= link_to_view( "[1 comment]", id);      }
            else
              { elt.innerHTML= link_to_view( "[" + nb + " comments]", id); }
          }
        else
          { alert("Problem retrieving XML data") }
      }
  }

function link_to_view ( text, id)
  { return "<a href=\"#c" + id + "\" onclick=\"view_comments(this, '" + id + "')\" title=\"view\">" + text + "</a>" }



function view_comments (elt, id)
  { 
    var url="/cgi-bin/comment?f=dc&amp;id=" + id;
    var xmlhttp
    // code for Mozilla, etc.
    if (window.XMLHttpRequest)
      { xmlhttp=new XMLHttpRequest()
        xmlhttp.onreadystatechange= function() { show_comments( xmlhttp, elt) }
        xmlhttp.open("GET",url,true)
        xmlhttp.send(null)
      }
    // code for IE
    else if (window.ActiveXObject)
      { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
        if (xmlhttp)
          { xmlhttp.onreadystatechange= function() { show_comments( xmlhttp, elt) }
            xmlhttp.open("GET",url,true)
            xmlhttp.send()
          }
      }
  }

function show_comments( xmlhttp, elt)
  { // if xmlhttp shows "loaded"
    if (xmlhttp.readyState==4)
      { // if "OK"
        if (xmlhttp.status==200)
          { // add the comments in their own div
            var div= document.createElement( "div")
            div.setAttribute( "id", "c"+ elt.id)
            var comments= xmlhttp.responseText
            div.innerHTML= comments
            elt.parentNode.insertBefore( div, elt)

            // add the link to hide the comments
            var hide= document.createElement( "a")
            var parent= this.parentNode
            hide.setAttribute( "onclick", "var parent= this.parentNode; parent.nextSibling.setAttribute( \"style\", \"display: inline\"); parent.parentNode.removeChild( parent);  ")
            var target= elt.parentNode.parentNode; // the links div
            hide.setAttribute( "href"   , "#" + target.id)
            hide.innerHTML= "[hide comments]"
            div.appendChild( hide)

            //hide the comment link
            elt.setAttribute( "style", "display: none");

            new Effect.SlideDown(div);
            
          }
        else
          { alert("Problem retrieving XML data") }
      }
  }

