// Use traditional event model whilst support for event registration
// amongst browsers is poor.

function addHandlers(id) {
	if(document.getElementById(id)){
		var objAnchor = document.getElementById(id);
	}
	if (objAnchor) {
		//objAnchor.firstChild.data = objAnchor.firstChild.data + ' (opens in a new window)';
		objAnchor.onclick = function(event){return launchWindow(this, event);}
		// UAAG requires that user agents handle events in a device-independent manner
		// but only some browsers do this, so add keyboard event to be sure
		objAnchor.onkeypress = function(event){return launchWindow(this, event);}
	}
}
function launchWindow(objAnchor, objEvent) {
	var iKeyCode, bSuccess=false;

	// If the event is from a keyboard, we only want to open the new window if the user requested the link (return or space)
	if (objEvent && objEvent.type == 'keypress') {
		if (objEvent.keyCode)
			iKeyCode = objEvent.keyCode;
		else if (objEvent.which)
			iKeyCode = objEvent.which;
		// If not carriage return or space, return true so that the user agent continues to process the action
		if (iKeyCode != 13 && iKeyCode != 32)
			return true;
	}
	//bSuccess = window.open(objAnchor.href);
	bSuccess = openWindow(objAnchor.href, objAnchor.title, 500, 600, objAnchor.id);
	// If the window did not open, allow the browser to continue the default action of opening in the same window
	if (!bSuccess)
		return true;
	// The window was opened, so stop the browser processing further
	return false;
}
function openWindow(url, title, height, width, name, parms) {
	var left = Math.floor( (screen.width - width) / 2);
	var top = Math.floor( (screen.height - height) / 2);
	var winParms = "top=" + top + ", left=" + left + ", height=" + height + ", width=" + width;
	if (parms) { winParms += "," + parms; }
	var win = window.open('', name, winParms);
	win.document.clear();
	win.focus();
	win.document.writeln('<html><head><title>'+title+'<\/title><\/head><body style=\"margin:0;padding:0;\">');
	win.document.writeln('<img src=\"'+url+'\" title=\"'+title+'\" alt=\"'+title+'\">');
	win.document.writeln('<\/body><\/html>');
	win.document.close();
	win.focus();
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
	return win;
}