/*****************************************************************************
*
* File     : LogPanel.js
* 
* Project  : WMS Viewer Client
* 
* Contents : 
*
* Author: Milan Trninic
*
* Copyright 1999-2005 Galdos Systems, Inc.
* All rights reserved.
* 
***|***************************|***********************|*******************|*/

/************************************************************************
*
*	Global declarations
*
*
*************************************************************************/
// This switch determines whether the panel and the button should be displayed
var LOG_ENABLED					= false;
// TIMER switch turns off or on the logging of timer data
var TIMER				= false;
//LOG switch turns off or on the logging of general (all except the timer) messages
var LOG					= false;
/************************************************************************
*
*	function:	LogPanel
*
*	purpose:	Constructor
*
*************************************************************************/
function LogPanel()
{
	// superclass
	var uiElement = document.getElementById("logPanel");
	this._superClass = StackedPanel;
	this._superClass(uiElement);
	
	// method assignments
	this.init = LogPanel.init;
	this.setSize = LogPanel.setSize;
	this.clear = LogPanel.clear;
	this.log = LogPanel.log;
	this.timerStart = LogPanel.timerStart;
	this.timerEnd = LogPanel.timerEnd;

	// instance field declarations
	this._logAreaUI;
	this._superClass;
	
	// initialization
	this.init();
}

/************************************************************************
*
*	function:	init
*
*	purpose:	initializes the globals
*
*************************************************************************/
function LogPanel.init()
{
	this._logAreaUI = document.getElementById("logArea");
	this.clear();
}

/************************************************************************
*
*	function:	setSize
*
*	purpose:	
*
*************************************************************************/
function LogPanel.setSize(width, height)
{
	// For explanation of the purpose of the temp variable, see the documentation
	this.temp = this._superClass.setSize;
	this.temp(width, height);
	//this._superClass.setSize(width, height);
	this._logAreaUI.style.height = height * 0.88;
	this._logAreaUI.style.width = width * 0.98;
}

/************************************************************************
*
*	function:	clear
*
*	purpose:	
*
*************************************************************************/
function LogPanel.clear()
{
	this._logAreaUI.value = "";
}

/************************************************************************
*
*	function:	log
*
*	purpose:	
*
*************************************************************************/
function LogPanel.log(message)
{
	if (LOG == false) return;
	this._logAreaUI.value += "\n" + message;
}

/************************************************************************
*
*	function:	timerStart
*
*	purpose:	
*
*************************************************************************/
function LogPanel.timerStart(message)
{
	if (TIMER == false) return null;
	if (message != null && message != "") this.log(message);
	var timerStart = new Date();
	return timerStart;
}

/************************************************************************
*
*	function:	timerEnd
*
*	purpose:	
*
*************************************************************************/
function LogPanel.timerEnd(message, timerStart)
{
	if (TIMER == false) return;
	var timerEnd = new Date();
	var elapsed = timerEnd.getTime() - timerStart.getTime();
	if (message == null) message = "";
	else if (message != "") message += " ";
	message += "Elapsed: " + elapsed + " ms.";
	this.log(message);

}

