// ************************************************************************************************************************************************************************
// Hottabych Bot (HotBolt) by Sasha Krassotkin (http://www.krassotkin.ru/) for Petr Tochilin (http://www.tochilin.ru/) specially for }{0TT@ÁÜ)× (http://www.hottabych.net/)
// Log.js (Log.*version*.js) is a part of Hottabych Bot (HotBolt) project.
// Log.js (Log.*version*.js) is a log utilities of javascript.
// Home of this version is http://www.hottabych.net/hotbolt/library/
// Home of this file is http://www.hottabych.net/hotbolt/library/Log.*version*.js
// Note! Hottabych@Bot is a Classic Model of chat Bots aka Eliza... but this implementation is mine ;-)
// Note! The following realizations of a Classic Model of chat Bots aka Eliza are known to us:
// - Chat Bot by George Dunlop, www.peccavi.com
// If you know other realizations send us the reference, please.
// May be free used/modified if credit line is retained 
// If you have created own addition or updating of this project or its part, send us it, please. 
// We shall make changes to files and we shall add the information about you in this file(s).
// © 2006 Public Domain (20061018)
// ************************************************************************************************************************************************************************

var Log = function (logElementID, logType, logPlace) { 
 this.completionStatus = 0;
 
 this.logType = logType;
 if(!this.logType) {this.logType = this.SYMPLE_TEXT_LOG_TYPE;}; 
 
 this.logPlace = logPlace;
 if(!this.logPlace) {this.logPlace = this.INTRO_ELEMENT_LOG_PLACE;}; 
 
 this.logElementID = logElementID;
 if(!logElementID) {
  this.completionStatus = -1;
 };
 
 this.logElement;
 this.createLogElement(); 
}

Log.prototype = new Root();

Log.prototype.SYMPLE_TEXT_LOG_TYPE = (Log.SYMPLE_TEXT_LOG_TYPE = 0);

Log.prototype.HIDDEN_LOG_PLACE = (Log.HIDDEN_LOG_PLACE = 0);
Log.prototype.INTRO_ELEMENT_LOG_PLACE = (Log.INTRO_ELEMENT_LOG_PLACE = 1);
Log.prototype.TOP_DOCUMENT_LOG_PLACE = (Log.TOP_DOCUMENT_LOG_PLACE = 2);
Log.prototype.BOTTOM_DOCUMENT_LOG_PLACE = (Log.BOTTOM_DOCUMENT_LOG_PLACE  = 3);

//-------------------------------------------------------------------------------
Log.prototype.completionStatus = 0;
Log.prototype.getCompletionStatus = function () {return this.completionStatus;};
Log.prototype.setCompletionStatus = function (completionStatus) {this.completionStatus = completionStatus;};

Log.prototype.println = function(text) {	
 if(!this.logElementID) {this.completionStatus = -100; return this.completionStatus;};
 if(!this.logElement) {
  this.createLogElement();
  if(!this.logElement) {
   return this.completionStatus;
  }
 };
 if(!this.logElement.appendChild) {this.completionStatus = -300; return this.completionStatus;};

 if(text == "") {text = " "};
 
 var textNode = document.createTextNode(text);
 var divElement = document.createElement("div");
 divElement.appendChild(textNode);
 this.logElement.appendChild(divElement);
 
 this.completionStatus = 1;
 return this.completionStatus;
}

Log.prototype.createLogElement = function() {
 if (this.logPlace == this.TOP_DOCUMENT_LOG_PLACE) {
  this.completionStatus =  this.createLogElementTop();
 } else if (this.logPlace == this.BOTTOM_DOCUMENT_LOG_PLACE) {
         this.completionStatus = this.createLogElementBottom();
        } else {
         ;
        }; 
 
 this.logElement = document.getElementById(this.logElementID);
 if(this.logElement) {this.completionStatus = 1;}
 else {
 };
 
 return this.completionStatus; 
}

Log.prototype.createLogElementTop = function() {
 var divElement = document.createElement("div");
 divElement.id = this.logElementID;
 var bodyElement = document.body;
 if(!bodyElement) {
  this.completionStatus = -1000000;
  return this.completionStatus;
 }
 var bodyFirstChild = bodyElement.firstChild;
 if(!bodyFirstChild) {
  this.completionStatus = -2000000;
  return this.completionStatus;
 }
 bodyElement.insertBefore (divElement, bodyFirstChild);
 this.completionStatus = 1;
 return this.completionStatus;
}

Log.prototype.createLogElementBottom = function() {
 var divElement = document.createElement("div");
 divElement.id = this.logElementID;
 divElement.style.textAlign = "left"
 var bodyElement = document.body;
 if(!bodyElement) {
  this.completionStatus = -100000000;
  return this.completionStatus;
 }
 bodyElement.appendChild(divElement);
 this.completionStatus = 1;
 return this.completionStatus;
}
