// JavaScript Document
// error logging as per Advanced DOM Scripting
function myLogger(id)  {
	id = id || 'FTPLogWindow';
	var logWindow = null;
	var createWindow = function()  {};
	this.createRaw = function(message) {};
	// protected method to create the window
	
	var createWindow = function()  {
		// get the left top position for the new window so it's centered in the browser
		var browserWindowSize = FTP.getBrowserWindowSize();
		var top = ((browserWindowSize.height - (-250)) / 2) || 0;
		var left = ((browserWindowSize.width - 200) / 2) || 0;
		
		// create the DOM node for the log window using the protected logWindow property to maintain a reference
		logWindow = document.createElement('UL');
		
		// position it centered on the screen
		logWindow.style.position = 'absolute';
		logWindow.style.top = top + 'px';
		logWindow.style.left = left + 'px';
		
		// give it a fixed and allow scrolling
		logWindow.style.width = '325px';
		logWindow.style.height = '200px';
		logWindow.style.overflow = 'scroll';
		logWindow.style.zindex = '15';
		
		// add some style to make it look a little nicer
		logWindow.style.padding = '0px';
		logWindow.style.margin = '0px';
		logWindow.style.border = '1px solid #000000';
		logWindow.style.backgroundColor = '#ffffff';
		logWindow.style.listStyle = 'none';
		logWindow.style.font = '10px/10px Verdana, Tahoma, sans-serif';
		
		// append it to the body
		document.body.appendChild(logWindow);
	};
	
	this.writeRaw = function(message)  {
		// if the initial window doesn't exist, creat it
		if(!logWindow) createWindow();
		
		// create the list item and style it appropriately
		var li = document.createElement('LI');
		li.style.padding = '2px';
		li.style.border = '0px';
		li.style.borderBottom = '1px dotted #000000';
		li.style.margin = '0px';
		li.style.color = '#000000';
		li.style.font = '9px / 9px Verdana, Tahoma, sans-serif';
		
		// add the message to the log mode
		if(typeof message == 'undefined')  {
			li.appendchild(document.createTextNode('Message was undefined'));
		} else if(typeof li.innerHTML != 'undefined')  {
				li.innerHTML = message;
		} else  {
				li.appendchild(document.createTextNode(message));
		}
		// append this entry to the log window
		logWindow.appendChild(li);
		
		return this;
	};
}
	
	myLogger.prototype = {
		write: function (message)  {
			// warn about null messages
			if (typeof message == 'string' && message.length == 0)  {
				return this.writeRaw('FTP.log: null message');
			}
			// if the message isn't a string try to call the toString() method, if it doesn't exist simply log the type of object
			if (typeof message != 'string')  {
				if (message.toString) return this.writeRaw(message.toString());
				else return this.writeRaw(typeof message);
			}
			// transform < and > so that .innerHTML doesn't parse the message as HTML
			message = message.replace(/</g, "&lt;").replace(/>/g, "&gt;");
			
			return this.writeRaw(message);
		},
		// write a simple header to the log window
		header: function(message)  {
			message = '<span style="color: #ffffff; background-color: #000000; font-weight: bold; padding: 0px 5px;">' + message + '</span>';
			
			return this.writeRaw(message);
		}
	};
// create an initial instance of the log object as FTPLog
if(!window.FTP)  {window['FTP'] = {}  }
window['FTP']['log'] = new myLogger();
if (!console) var console =FTP.log;