
if (isJsEnabled()) {
  addLoadEvent(clickCommentsAutoAttach);
}


function clickCommentsAutoAttach() {
//alert("yo");
  var cidb = [];
  var spans = document.getElementsByTagName('span');
  for (var i = 0; span = spans[i]; i++) {
    if (span && hasClass(span, 'clickComments')) {
      // Read in the path to the PHP handler
      uri = span.getAttribute('title');
      // Remove the title, so no tooltip will display
      span.removeAttribute('title');
      // Create an object with this uri. Because
      // we feed in the span as an argument, we'll be able
      // to attach events to this element.
      if (!cidb[uri]) {
        cidb[uri] = new CIDB(span, uri);
      }
    }
  }
}

/**
 * A click info DataBase object
 */
function CIDB(elt, uri) {
  var db = this;
  // By making the span element a property of this object,
  // we get the ability to attach behaviours to that element.
  this.elt= elt;
  this.uri = uri;
  this.elt.onclick = function() {
    HTTPGet(db.uri, db.receive, db);
  }
}

/**
 * HTTP callback function. Raises an a-lert box
 */
CIDB.prototype.receive = function(string, xmlhttp, cidb) {
  if (xmlhttp.status != 200) {
    return alert('An HTTP error '+ xmlhttp.status +' occured.\n'+ cidb.uri);
  }
  // We have access to the span element, since it's an attribute of the cidb object.
  // Remove the 'clickInfo' class, to show that this is already clicked.
  // We do this with another of the functions in drupal.js
  removeClass(cidb.elt, 'clickInfo');
  alert(string);
}



