// Chris Pyper 2006
// Debugging functions

/*
function debug(message)
{
	if(!debugOn)
	{
		// Remove it if it exists
		if(debugWindow)
		{
			debugWindow.parentNode.removeChild(debugWindow);
			debugWindow = false;
		}
		return false;
	}

	if(!debugWindow)
	{
		var div = document.createElement("div");
		div.id = 'debugWindow';
		document.body.appendChild(div);
		debugWindow = document.getElementById('debugWindow');
		debugWindow.style.backgroundColor = 'white';
		debugWindow.style.position = 'absolute';
		debugWindow.style.top = '0px';
		debugWindow.style.left = '0px';
		debugWindow.style.width = '500px';
		debugWindow.style.height = '200px';
		debugWindow.style.overflow = 'scroll';
	}

	var current = debugWindow.innerHTML;
	var newMessage = message + "<br/>" + current;
	newMessage = newMessage.substr(0, 4000);
	debugWindow.innerHTML = newMessage;
}
*/

function debug(message, level)
{
    if(!debugOn)
        return false;

	if(!level)
		level = 'error';

    if(!debugWindow)
    {
        var div = document.createElement("div");
		div.style.top = '0px';
		div.style.left = '0px';
		div.style.position = 'absolute';
        div.id = 'debugWindow';
        document.body.appendChild(div);

		debugWindow = new YAHOO.widget.LogReader(div); 
    }
	else
		YAHOO.log(message, level);
}

function testEvent(e)
{
	debug('***TEST EVENT***');
}

// Debug has to be on for this to work
function printAllEvents(docRef)
{
    if (docRef)
    {
		if(docRef.onclick)
			debug('EVENT onclick ' + docRef.tagName + ' ' + trimEvent(docRef.onclick));
		if(docRef.onmousedown)
			debug('EVENT onmousedown ' + docRef.tagName + ' ' + trimEvent(docRef.onmousedown));
		if(docRef.onmouseup)
			debug('EVENT onmouseup ' + docRef.tagName + ' ' + trimEvent(docRef.onmouseup));
		if(docRef.onclick)
			debug('EVENT ondblclick ' + docRef.tagName + ' ' + trimEvent(docRef.ondblclick));
		if(docRef.onmousemove)
			debug('EVENT onmousemove ' + docRef.tagName + ' ' + trimEvent(docRef.onmousemove));
	}

    // Now get all children of docref
    var children = docRef.childNodes;

    // Loop through the children and recurse the children
    for(var i = 0; i < children.length; i++)
        printAllEvents(children[i]);
}

function trimEvent(eventString)
{
	eventString = eventString + ' ';
	var stringArray = new Array();
	stringArray = eventString.split("\n");
	var firstLine = stringArray[0];
	return firstLine;
}

