
//var DEFAULT_LOG_URL="/servlet/jsLog";
var DEFAULT_LOG_URL="/cgi-bin/comments.pl";
var jsLogStatus = true;

function error()
{
  alert("Could not perform Ajax call to jsLog servlet");
}

function myHandler(txt, xmlDoc)
{

}

function jsLogOn()
{
  jsLogStatus = true;  
}

function jsLogOff()
{
  jsLogStatus = false;  
}

function jslogInfo(o,u)
{
  if (!jsLogStatus) return;

  var uri=DEFAULT_LOG_URL;
  if (u!=null) uri=u;

  var data = encodeURI(""+o);
  //.getTime()
  cjAjaxEngine(uri+"?dt="+data+"&cntcj="+new Date(),myHandler,error);

  return false;
}

function cjAjaxEngine(uri,handlerFunction,errorFunction)
{
  cjAjaxEngine(uri,handlerFunction,errorFunction,null,null);
}

function cjAjaxEngine(uri,handlerFunction,errorFunction,beforeAction,afterAction)
{
  if (handlerFunction==null)  handlerFunction = function() {};
  if (errorFunction==null)    errorFunction = function () {};

  if (beforeAction == null) beforeAction = function() {};
  if (afterAction == null) afterAction = function() {};

  var r = (window.ActiveXObject)?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest();
  if (r)
  {
    r.onreadystatechange = function()
    {     
	if (r.readyState == 4)
        {
         afterAction(); 
         if (r.status == 200)
  	 {
	   xmlDoc = r.responseXML;				
           txt = r.responseText;
           handlerFunction(txt, xmlDoc);
	 }
         else
          errorFunction();
       }
    }
    beforeAction(); 
    r.open("GET", uri);
    //r.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    if (window.XMLHttpRequest) r.send(null);
    else                       r.send();
    return true;
  }
  else
  {
    errorFunction();
    return false;
  }
}

