//===================================================================
// _RegisterEvent - a cooperative, cross-browser event registration
//                  method
//
//  input
//    szEventName	- An event available on the window object.
//    pEventHandler	- The handler function to register with event.
//
function _RegisterEvent(szEventName, pEventHandler)
{
	// get the existing registered handler
	var handler1 = eval("this." + szEventName);

	if(typeof(attachEvent) != "undefined")
	{
		// this is IE 5.0 or later. Cooperative Registration is easy
		eval("this.attachEvent('" + szEventName + "', " + pEventHandler + ");");
		return;
	}
	else if(typeof(addEventListener) != "undefined")
	{
		// this is Netscape 6.0 or later. Cooperative Registration is easy
		eval("this.addEventListener('" + (szEventName.substring(2)) + "', " + pEventHandler + ", false);");
		return;
	}
	// Custom event Registration layer required for cooperation, but first
	// check if there is an existing function attached to the event.
	else if(!handler1)
	{
		// This will be the first function attached to the event
		// Registration is easy and does not need to cooperate
		eval("this." + szEventName + " = pEventHandler");
		return;
	}
	// There is an existing function, we need it as a string.
	else
	{
		handler1 = handler1.toString();
	}

	// Get the new function to attach as a string.
	var handler2 = pEventHandler.toString();

	// Combine the 2 functions into 1 new function.
	var ev;
	ev=handler1.substring(handler1.indexOf("{") + 1, handler1.lastIndexOf("}")) + handler2.substring(handler2.indexOf("{") + 1, handler2.lastIndexOf("}"));
	ev=new Function(ev);

	// Assign the new function to the event.
	eval("this." + szEventName + " = ev");
}

if(typeof(window.RegisterEvent) == "undefined")
	window.RegisterEvent = _RegisterEvent;
if(typeof(document.RegisterEvent) == "undefined")
	document.RegisterEvent = _RegisterEvent;

// Copyright 2002 Coalesys Inc. This code may be copied freely and used to create derived
//   works. Contact author at info@coalesys.com for questions.


/*

Eksempel:

Kode:
function myGreeter(p_who) {
	alert('Hello ' + p_who);
}

function myDoOnload(e) {
	myGreeter('World');
}

Hvis jeg gerne vil tilføje funktion som skal udføres på eventet body.onload, så bruges dette:

window.RegisterEvent("onload", "myDoOnload");

Læg mærke til at myDoOnload er hæftet på uden parametre, 
dette er et KRAV, derfor kaldes myDoOnload istedet for direkte at knytte myGreeter('World'),
direkte med RegisterEvent.

Dvs. at myDoOnload's indhold skal renderes server-side, til at indehold alt det vi gerne vil udføre,
med de parametre man har lyst til.
*/