function DM(m){
	debugHelper.Message(m+'<br>');
}function DW(m){
	debugHelper.Warn(m);
}


//debug helper class to control popup windows
var DebugHelper = function()
{
    this.Active = true;
    this.ShowException = true;
    this.ShowURL = true;
    this.ShowLastModified = false;
    this.ShowReferrer = false;
    this.VerboseMode = true;
    //reference to the popup window
    this.DebugWindow = null;
    this.CssStyleFile = new String("debugWindow.css");
    this.WindowStyle = new String("xleft=0,xtop=0,width=300,height=300,scrollbars=yes,status=no,resizable=yes");
    //no spaces to run correctly on internet explorer
    this.WindowName = new String("JavascriptDebugWindow");
    this.WindowTitle = new String("Javascript Debug Window");
}


//method to show the debug window
DebugHelper.prototype.ShowWindow = function()
{
	try
	{
	    if( this.Active )
	    {
		    this.DebugWindow = window.open("", this.WindowName, this.WindowStyle);
	  	    this.DebugWindow.opener = window;
	  	    //open the document for writing
	  	    this.DebugWindow.document.open();
	  	    this.DebugWindow.document.write(
	    	    "<html><head><title>" + this.WindowTitle + "</title>" +
	    	    "<link rel='stylesheet' type='text/css' href='" + this.CssStyleFile + "' />" + 
	    	    "</head><body><div id='renderSurface' style='width: 100%; height: 100%;' /></body></html>\n"
	        );
    	    this.DebugWindow.document.close();
	    }
	}
	catch(ex)
	{
	    alert(ex.message);
		//ignore exception
	}
}		

//if the debug window exists, then write to it
DebugHelper.prototype.$Write = function(cssClass, message, url, lastModified, referrer) 
{
	try
	{
		if( this.Active )
		{
			if( this.DebugWindow && ! this.DebugWindow.closed )
			{
			    var msg = message;
			    
			    if( this.ShowURL && url != null )
			        msg += " at " + url;
			        
			    if( this.ShowLastModified && lastModified != null )
			        msg += " last modified in " + lastModified;

			    if( this.ShowReferrer && referrer != null )
			        msg += " referrer " + referrer;

		    	this.DebugWindow.document.getElementById("renderSurface").innerHTML = "<span class='" + cssClass + "'>" + msg + "</span>" + this.DebugWindow.document.getElementById("renderSurface").innerHTML;
		  	}
		}
	}
	catch(ex)
	{
		//ignore exception
	}
}

//write a message to debug window
DebugHelper.prototype.Message = function(message, url, lastModified, referrer)
{
	try
	{
    	this.$Write("debugMessage", message, url, lastModified, referrer);
	}
	catch(ex)
	{
		//ignore exception
	}
}

//same as debug, plus another style applyied
DebugHelper.prototype.Warn = function(message, url, lastModified, referrer)
{
	try
	{
    	this.$Write("debugWarn", message, url, lastModified, referrer);
	}
	catch(ex)
	{
		//ignore exception
	}
}

//same as debug, plus a strong style applyied
DebugHelper.prototype.Exception = function(message, url, lastModified, referrer)
{
	try
	{
	    if( this.ShowException )
	    {
    	    this.$Write("debugException", message, url, lastModified, referrer);
    	}
	}
	catch(ex)
	{
		//ignore exception
	}
}

//if the debug window exists, then close it
DebugHelper.prototype.HideWindow = function() 
{
	try
	{
	    if( this.DebugWindow && !this.DebugWindow.closed )
	    {
		    this.DebugWindow.close();
    	    this.DebugWindow = null;
  	    }
	}
	catch(ex)
	{
		//ignore exception
	}
}

//create a global debug object
var debugHelper = new DebugHelper();