//------------------------------------------------------------------------------
// PHASE I: INCLUDE ALL NECESSARY JAVASCRIPT FILES.
//------------------------------------------------------------------------------
document.write("<script src='/inc/jscripts/cms.event.js'></script>");
document.write("<script src='/inc/jscripts/cms.functions.js'></script>");
document.write("<script src='/inc/jscripts/checkfields.js'></script>");
document.write("<script src='/inc/jscripts/newwin.js'></script>");

//------------------------------------------------------------------------------
// PHASE II: INITIALIZATION FUNCTION, CALLED ON WINDOW LOAD EVENT
//------------------------------------------------------------------------------

/**
 * Initialize the page.
 * 
 * This function gets all tagnames that have the 'setnewwin' attribute set to
 * 'yes' and adds an onclick eventhandler that calls the newwin function with
 * the href value as the url to load in the new window.
 * 
 * @param		type	var
 * @return	type	var
 * @access	public/private
 */
function init() {
	var anchors,		// array of anchor elements with 'setnewwin' set to true.
			i;					// iterator.
	
	anchors = document.getElementsByAttribute('setnewwin', 'yes', 'a');
	if ( anchors.length ) {
		for ( i = 0; i < anchors.length; i++ ) {
			addEvent(anchors[i], 'click', handleResultClick);
		}
	}
} // init()

/**
 * Eventhandler for the click event on searchresults. Eventhandler is added in
 * init() function.
 * 
 * 
 * @param		object		[e]		event object for Mozilla-based browers.
 * @return	false						stop further event execution.
 * @access	public/private
 */
function handleResultClick(e) {
	var eventSrc,		// DOM element that fired this event.
			href;				// href attribute of event source.

	if ( !e ) e = window.event;
	var eventSrc = getEventSrc(e);
	if ( is_object(eventSrc) ) {
		href = eventSrc.getAttribute('href');
		// add flag to tell that highlight was opened in a new window. We use this
		// information to print a "back to overview" button if the highlight was
		// NOT opened in a new window.
		href += '&innewwin=1';
		newwin(href, 500, 500, 'avshighlight');
	}

	if ( e.preventDefault ) e.preventDefault();
	return false;
} // handleResultClick()

window.onload = init;