
 var jsLog = jsLog || { }


 jsLog.DEFAULT_LOG_URL="/servlet/jsLog";
 jsLog.MAX_DUMP_DEPTH = 10;
 jsLog.jsLogStatus = true;
 jsLog.url = jsLog.DEFAULT_LOG_URL;

 jsLog.error = function()
  {
    alert("Could not perform Ajax call to jsLog servlet");
  };

 jsLog.setURL =  function (_url)
  {
    jsLog.url = _url;
  };

 jsLog.getURL = function()
  {
    return jsLog.url;
  };

 jsLog.On = function()
  {
    jsLog.jsLogStatus = true;  
  };

 jsLog.Off = function ()
  {
    jsLog.jsLogStatus = false;  
  };

 jsLog.myHandler = function (txt, xmlDoc)
 {

 }

 jsLog.Info = function (o,_title,u)
 {
  if (!jsLog.jsLogStatus) return;

  var uri=jsLog.DEFAULT_LOG_URL;
  if (u) uri=u;

  var title = "";
  if (_title)
  {
    title = _title; 
  }

  var data = encodeURI(title+": "+jsLog.dumpObj(o, "", "", jsLog.MAX_DEPTH));

  jsLog.cjAjaxEngine(uri+"?dt="+data+"&cntcj="+new Date().getTime(),jsLog.myHandler,jsLog.error);

  return false;
 }

 jsLog.cjAjaxEngine = function (uri,handlerFunction,errorFunction)
 {
  jsLog.cjAjaxEngine(uri,handlerFunction,errorFunction,null,null);
 }

 jsLog.cjAjaxEngine = function (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;
  }
}

 jsLog.dumpObj = function(obj, name, indent, depth) {

              if (depth > jsLog.MAX_DUMP_DEPTH) {
                     return indent + name + ": <Maximum Depth Reached>\n";
              }

              if (typeof obj == "object") {
                     var child = null;
                     var output = indent + name + "\n";
                     indent += "\t";
                     for (var item in obj)
                     {
                           try {
                                  child = obj[item];
                           } catch (e) {
                                  child = "<Unable to Evaluate>";
                           }
                           if (typeof child == "object") {

                                  output += dumpObj(child, item, indent, depth + 1);
                           } else {

                                  output += indent + item + ": " + child + "\n";
                           }

                     }
                     return output;

              } else {
                     return obj;
              }

       }
 


