/******************************************************************************
 *
 *                   INDIGEN SOLUTIONS CODE PROPERTY
 *       The present javascript code is property of Indigen Solutions. This 
 *     code can only be used inside Internet/Intranet web sites located on 
 *  *web servers*, as the outcome of a licensed Indigen Solutions application 
 *  only. Any unauthorized use, reverse-engineering, alteration, transmission, 
 * transformation, facsimile, or copying of any means (electronic or not) is 
 *     strictly prohibited and will be prosecuted. Removal of the present 
 *              copyright notice is strictly prohibited
 *         Copyright (c) 2004 Indigen Solutions. All Rights Reserved.
 *
 * RCS Id   $Id: log.js,v 1.13 2006/07/01 06:45:51 jerome Exp $
 * RCS Revision                 $Revision: 1.13 $
 * RCS Check in date            $Date: 2006/07/01 06:45:51 $
 * 
 ******************************************************************************/

var IJSLogger = null;

if ( IJSLogger == null) {

  function IJSLoggerObject() {

    /* Globals. */
    
    this.panel   = null;
    this.div     = null;
    this.content = "";
    this.times   = {};
    
    /* Methods. */
    
    this.debug = function(messsage) {
      this._writeLog("debug", messsage);
    };
    
    this.debugHTML = function(html) {
      if (html) {
	html = html.replace(/</gi, "&lt;");
	html = html.replace(/>/gi, "&gt;");
	html = "<br>================================================================<br>" + 
	       html + "<br>================================================================";
	this._writeLog("debugHTML", html);
      } else {
	this._writeLog("debugHTML", "Empty HTML");
      }
    };

    this.startTime = function(name) {
      this.times[name] = new Date();
    };

    this.showTime = function(name) {
      var oldDate = this.times[name];
      var date = new Date();
      this.debug('Time ======> ' + name + ' : ' + (date - oldDate) + ' ms');
    };

    /* Internal. */

    this._writeLog = function(type, str) {
      if (JSDEBUG) {
	this._createPanelPopup();
	if (this.content.length > 1000000)
	  this.content = "";
	var date = new Date();
	this.content += "<br><b>["+type+"]" + date + " :   </b>" + str;      
	try {
	  this.div.innerHTML = this.content;
	} catch (e) {
	}
      }
    };

    this._createPanelDiv = function() {
      if (JSDEBUG) {
	try { 
	  if (this.panel.document) {}
	} catch(e) {
	  try {
	    this.panel = null;
	    this.panel = document.createElement("div");
	    this.panel.style.position = "absolute";
	    this.panel.style.top = "0px";
	    this.panel.style.left = "1200px";
	    this.panel.style.width = "600px";
	    this.panel.style.height = "600px";
	    document.body.insertBefore(this.panel);
	    this.div = this.panel.document.createElement("div");
	    this.div.style.width = "100%";
	    this.div.style.height = "100%";
	    this.div.style.overflow = "auto";
	    this.div.style.border = "2px inset";
	    this.panel.appendChild(this.div);    	  
	  } catch (e) {	  
	  }
	}
      }  
    }

    this._createPanelPopup = function() {
      if (JSDEBUG) {
	try { 
	  if (this.panel.document) {}
	} catch(e) {
	  try {
	    this.panel = null;
	    this.panel = window.open("about:blank", this.panel);
	    this.panel.document.write("<html><body></body></html>");
	    this.div = this.panel.document.createElement("div");
	    this.div.style.width = "100%";
	    this.div.style.height = "100%";
	    this.div.style.overflow = "auto";
	    this.div.style.border = "2px inset";
	    this.panel.document.body.appendChild(this.div);    	  
	  } catch (e) {
	  
	  }
	}
      }  
    };
  }
  IJSLogger = new IJSLoggerObject();
}
