function NotifyEvent(initial_value, initial_value_2)
{
  this.callbacks = new Array();
  this.value = initial_value;
  this.value2 = initial_value_2;
  this.registerCb = function(callback)
  {
    this.callbacks[this.callbacks.length] = callback;
  }
  this.notify = function(value, value2)
  {
    var cb;
    this.value = value;
    this.value2 = value2;
    for (cb in this.callbacks) {
      this.callbacks[cb](value, value2);
    }
  }
}

var comment_list_changed_event = new NotifyEvent(null);
var isSafari = navigator.appVersion.match("AppleWebKit");
var isIE = navigator.appVersion.match("MSIE");

// Avoid overcaching the actions (seems to be a Safari problem).
var start_time = new Date();
var roxen_magic_timestamp = start_time.getTime();
var roxen_magic_counter = 0;

function xmlhttpRequest(filepath, callback, post_data)
{
  var xmlhttp;
  method = post_data ? "POST" : "GET";
  if(window.XMLHttpRequest) { // Mozilla, Safari, ...
    xmlhttp = new XMLHttpRequest();
  }
  else if (window.ActiveXObject) { // IE
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  
  if (filepath.indexOf("?") != -1) { // We have a query string.
    // Hook in the broken Safari detector.
    filepath += "&roxen_magic_per_u=%u270c";
  }
  
  // Avoid overcaching the actions (seems to be a Safari problem).
  filepath += "&roxen_magic_timestamp="+roxen_magic_timestamp;
  filepath += "&roxen_magic_counter="+roxen_magic_counter;
  roxen_magic_counter++;
  
  xmlhttp.open(method, filepath, true);
  xmlhttp.onreadystatechange = function() {
    var value = callback(xmlhttp);
    return value;
  };
  
  if (method == "GET")
    xmlhttp.send(null);
  else {
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send(post_data);
  }
}

function getResponseXML(xmlhttp) {
  var doc;

  if(!document.importNode){
    document._importNode = function(oNode, bImportChildren){
      var oNew;      
      if(oNode.nodeType == 1){
	oNew = document.createElement(oNode.nodeName);
	for(var i = 0; i < oNode.attributes.length; i++){
	  oNew.setAttribute(oNode.attributes[i].name, oNode.attributes[i].value);
	}
	//oNew.style.cssText = oNode.style.cssText;
      }
      else if(oNode.nodeType == 3){
	oNew = document.createTextNode(oNode.nodeValue);
      }
      if(bImportChildren && oNode.hasChildNodes()){
	for(var oChild = oNode.firstChild; oChild; oChild = oChild.nextSibling){
	  oNew.appendChild(document._importNode(oChild, true));
	}
      }
      return oNew;
    }
    doc = document._importNode(xmlhttp.responseXML.documentElement, true);
  }
  else {
    doc = document.importNode(xmlhttp.responseXML.documentElement, true);
    
    if(isSafari) {
      // Safari doesn't initialise all node attributes (name, class etc.)
      // properly without this workaround.
      doc.innerHTML = doc.innerHTML;
    }
  }
  return doc;
}
