
Object.extend(Event, {
	_domReady : function() {
		if (arguments.callee.done) return;
		arguments.callee.done = true;
		if (this._timer) clearInterval(this._timer);
		this._readyCallbacks.each(function(f) { f() });
		this._readyCallbacks = null;
	},

	onDOMReady : function(f) {
		if (!this._readyCallbacks) {
			var domReady = this._domReady.bind(this);

			if (document.addEventListener) document.addEventListener("DOMContentLoaded", domReady, false);

			/*@cc_on @*/
			/*@if (@_win32)
				document.write("<script id=__ie_onload defer='true' src='javascript:void(0)'><\/script>");
				document.getElementById("__ie_onload").onreadystatechange = function() { if (this.readyState == "complete") domReady(); };
			/*@end @*/

			if (/WebKit/i.test(navigator.userAgent)) this._timer = setInterval(function() {if (/loaded|complete/.test(document.readyState)) domReady(); }, 10);

			Event.observe(window, 'load', domReady);
			Event._readyCallbacks =  [];
		}

		Event._readyCallbacks.push(f);
	}
});


/* ======================================================================== */


var BMJ = function(){

	return {

		/* -- BEGIN: DHTMLMenu ------------------------------------------------ */
		DHTMLMenu : function() {
			
			var CONFIG = {
				menu_id : "MainNav", // the DOM ID of the menu container
				hover_class : "Hover", // the class to give the top-level LI to "activate" the menu
				menu_time : 500 // time to keep the menus on after mouseout; in ms
			};

			return {
				menu_timeout : null, // the JS timeout ID for hiding the menu
				last_menu_on : null, // the DOM object of the waiting to close

				// initialize the menus. usually called on page load / DOM ready
				init : function() {
					// bail out if the menu doesn't exist on this page
					if (!$(CONFIG["menu_id"])) return;

					// get all the top-level LIs in the menu
					var menu_items = $(CONFIG["menu_id"]).cleanWhitespace().childNodes;

					// iterate over them and add event handlers
					$A(menu_items).each(function(item){
						Element.cleanWhitespace(item);

						// the mouseover
						Event.observe(item, "mouseover", function(e) {
							var el = Event.element(e);

							// stop the menu from closing (this gets called a lot)
							clearTimeout(this.menu_timeout);

							// show the menu
							this.showMenu(item);


						}.bind(this), false); // END: mouseover

						// the mouseout
						Event.observe(item, "mouseout", function(e) {
							var el = Event.element(e);

							// store the last item on
							this.last_menu_on = item;

							var turnOff = function() {
								this.hideMenu(item);
								this.last_menu_on = null;
							}.bind(this);

							// only "close" the menu in a little bit if we're over a menu with submenus, otherwise, close it right now
							if ( (el.parentNode.id && (el.parentNode.childNodes.length > 1)) || (el.parentNode.childNodes.length > 1) ) {
								this.menu_timeout = setTimeout(turnOff,	CONFIG["menu_time"]);

							} else {
								turnOff();
							}

						}.bind(this), false); // END: mouseout

					}.bind(this)); // END: each()
				}, // END: init()

				// shows the menu
				showMenu : function(item) {
					// hide the last menu shown
					if (this.last_menu_on != null) this.hideMenu(this.last_menu_on);

					// adding the "hover" class turns on the menu
					$(item.id).addClassName(CONFIG['hover_class']);
				}, // END: showMenu()

				// hide the menu
				hideMenu : function(item) {
					if (item == null) return;

					// removing the "hover" class turns off the menu
					$(item.id).removeClassName(CONFIG['hover_class']);
				} // END: hideMenu()

			} // END: return
		}()
		/* -------------------------------------------------- END: DHTMLMenu -- */

	} // END: return
}(); // END: HBSP namespace


Event.onDOMReady(function() {
	// simple mouseovers/outs
	BMJ.DHTMLMenu.init();
});



function submitResourceForm(form) {
	// If they didn't select the default "---Select--" item, submit the form
	if(form.resource_name.selectedIndex != 0) {
		form.submit();	
	}
}

/* - register_function.js - */
// http://edit.bmjpg.com/portal_javascripts/register_function.js?original=1
var bugRiddenCrashPronePieceOfJunk=(navigator.userAgent.indexOf('MSIE 5')!=-1&&navigator.userAgent.indexOf('Mac')!=-1)
var W3CDOM=(!bugRiddenCrashPronePieceOfJunk&&typeof document.getElementsByTagName!='undefined'&&typeof document.createElement!='undefined');var registerEventListener=null;if(typeof addEvent!='undefined'){registerEventListener=function(elem,event,func){addEvent(elem,event,func);return true}} else if(window.addEventListener){registerEventListener=function(elem,event,func){elem.addEventListener(event,func,false);return true}} else if(window.attachEvent){registerEventListener=function(elem,event,func){var result=elem.attachEvent("on"+event,func);return result}} else{registerEventListener=function(elem,event,func){return false}}
var unRegisterEventListener=null;if(typeof removeEvent!='undefined'){unRegisterEventListener=function(elem,event,func){removeEvent(element,event,func);return true}} else if(window.removeEventListener){unRegisterEventListener=function(elem,event,func){elem.removeEventListener(event,func,false);return true}} else if(window.detachEvent){unRegisterEventListener=function(elem,event,func){var result=elem.detachEvent("on"+event,func);return result}} else{unRegisterEventListener=function(elem,event,func){return false}}
var registerPloneFunction=null;if(typeof addDOMLoadEvent!='undefined'){registerPloneFunction=function(func){addDOMLoadEvent(func)}} else{registerPloneFunction=function(func){registerEventListener(window,"load",func)}}
function getContentArea(){if(W3CDOM){var node=document.getElementById('region-content');if(!node){node=document.getElementById('content')}
return node}}


/* - nodeutilities.js - */
// http://edit.bmjpg.com/portal_javascripts/nodeutilities.js?original=1
function wrapNode(node,wrappertype,wrapperclass){var wrapper=document.createElement(wrappertype)
wrapper.className=wrapperclass;var innerNode=node.parentNode.replaceChild(wrapper,node);wrapper.appendChild(innerNode)};
function nodeContained(innernode,outernode){var node=innernode.parentNode;while(node!=document){if(node==outernode){return true}
node=node.parentNode}
return false};
function findContainer(node,func){while(node!=null){if(func(node)){return node}
node=node.parentNode}
return false};
function hasClassName(node,class_name){return new RegExp('\\b'+class_name+'\\b').test(node.className)};
function addClassName(node,class_name){if(!node.className){node.className=class_name} else if(!hasClassName(node,class_name)){var className=node.className+" "+class_name;node.className=className.split(/\s+/).join(' ')}};
function removeClassName(node,class_name){var className=node.className;if(className){className=className.replace(new RegExp('\\b'+class_name+'\\b'),'');className=className.replace(/\s+/g,' ');node.className=className.replace(/\s+$/g,'')}};
function replaceClassName(node,old_class,new_class,ignore_missing){if(ignore_missing&&!hasClassName(node,old_class)){addClassName(node,new_class)} else{var className=node.className;if(className){className=className.replace(new RegExp('\\b'+old_class+'\\b'),new_class);className=className.replace(/\s+/g,' ');node.className=className.replace(/\s+$/g,'')}}};
function walkTextNodes(node,func,data){if(!node){return false}
if(node.hasChildNodes){for(var i=0;i<node.childNodes.length;i++){walkTextNodes(node.childNodes[i],func,data)}
if(node.nodeType==3){func(node,data)}}};
function getInnerTextCompatible(node){var result=new Array();walkTextNodes(node,
function(n,d){d.push(n.nodeValue)},result);return result.join("")};
function getInnerTextFast(node){if(node.innerText){return node.innerText} else{return getInnerTextCompatible(node)}};
function sortNodes(nodes,fetch_func,cmp_func){if(!W3CDOM){return false};var SortNodeWrapper=function(node){this.value=fetch_func(node);this.cloned_node=node.cloneNode(true);this.toString=function(){if(this.value.toString){return this.value.toString()} else{return this.value}}}
var items=new Array();for(var i=0;i<nodes.length;i++){items.push(new SortNodeWrapper(nodes[i]))}
if(cmp_func){items.sort(cmp_func)} else{items.sort()}
for(var i=0;i<items.length;i++){var dest=nodes[i];dest.parentNode.replaceChild(items[i].cloned_node,dest)}};


/* - highlightsearchterms.js - */
// http://edit.bmjpg.com/portal_javascripts/highlightsearchterms.js?original=1
function highlightTermInNode(node,word){var contents=node.nodeValue;var index=contents.toLowerCase().indexOf(word.toLowerCase());if(index<0){return false};var parent=node.parentNode;if(parent.className!="highlightedSearchTerm"){var hiword=document.createElement("span");hiword.className="highlightedSearchTerm";hiword.appendChild(document.createTextNode(contents.substr(index,word.length)));parent.insertBefore(document.createTextNode(contents.substr(0,index)),node);parent.insertBefore(hiword,node);parent.insertBefore(document.createTextNode(contents.substr(index+word.length)),node);parent.removeChild(node)}}
function highlightSearchTerms(terms,startnode){if(!W3CDOM){return false};if(!terms){return false};if(!startnode){return false};for(var term_index=0;term_index<terms.length;term_index++){var term=terms[term_index];if(term.length<1)
continue;var term_lower=term.toLowerCase();if(term_lower!='not'&&term_lower!='and'&&term_lower!='or'){walkTextNodes(startnode,highlightTermInNode,term)}}}
function getSearchTermsFromURI(uri){var query;if(typeof decodeURI!='undefined'){query=decodeURI(uri)} else if(typeof unescape!='undefined'){query=unescape(uri)} else{}
var result=new Array();if(window.decodeReferrer){var referrerSearch=decodeReferrer();if(null!=referrerSearch&&referrerSearch.length>0){result=referrerSearch}}
var qfinder=new RegExp("searchterm=([^&]*)","gi");var qq=qfinder.exec(query);if(qq&&qq[1]){var terms=qq[1].replace(/\+/g,' ').split(/\s+/);for(var i=0;i<terms.length;i++){if(terms[i]!=''){result.push(terms[i])}}
return result}
return result.length==0?false:result}
function highlightSearchTermsFromURI(){if(!W3CDOM){return false};var terms=getSearchTermsFromURI(window.location.search);var contentarea=getContentArea();highlightSearchTerms(terms,contentarea)}
registerPloneFunction(highlightSearchTermsFromURI);

/* - se-highlight.js - */
// http://edit.bmjpg.com/portal_javascripts/se-highlight.js?original=1
var searchEngines=[['^http://([^.]+\\.)?google.*','q='],['^http://search\\.yahoo.*','p='],['^http://search\\.msn.*','q='],['^http://search\\.aol.*','userQuery='],['^http://(www\\.)?altavista.*','q='],['^http://(www\\.)?feedster.*','q='],['^http://search\\.lycos.*','query='],['^http://(www\\.)?alltheweb.*','q='],['^http://(www\\.)?ask\\.com.*','q=']]
function decodeReferrer(ref){if(null==ref&&document.referrer){ref=document.referrer}
if(!ref) return null;var match=new RegExp('');var seQuery='';for(var i=0;i<searchEngines.length;i++){if(!match.compile){match=new RegExp(searchEngines[i][0],'i')} else{match.compile(searchEngines[i][0],'i')}
if(ref.match(match)){if(!match.compile){match=new RegExp('^.*[?&]'+searchEngines[i][1]+'([^&]+)&?.*$','i')} else{match.compile('^.*[?&]'+searchEngines[i][1]+'([^&]+)&?.*$')}
seQuery=ref.replace(match,'$1');if(seQuery){seQuery=decodeURIComponent(seQuery);seQuery=seQuery.replace(/\'|"/, '');return seQuery.split(/[\s,\+\.]+/)}}}
return null}

/* - styleswitcher.js - */
// http://edit.bmjpg.com/portal_javascripts/styleswitcher.js?original=1
function setActiveStyleSheet(title,reset){if(!W3CDOM){return false};var i,a,main;for(i=0;(a=document.getElementsByTagName("link")[i]);i++){if(a.getAttribute("rel").indexOf("style")!=-1&&a.getAttribute("title")){a.disabled=true;if(a.getAttribute("title")==title){a.disabled=false}}}
if(reset==1){createCookie("wstyle",title,365)}};
function setStyle(){var style=readCookie("wstyle");if(style!=null){setActiveStyleSheet(style,0)}};registerPloneFunction(setStyle);

function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' '){c=c.substring(1,c.length)}
if(c.indexOf(nameEQ)==0){return unescape(c.substring(nameEQ.length,c.length))}}
return null};

/* - cookie_functions.js - */
// http://edit.bmjpg.com/portal_javascripts/cookie_functions.js?original=1
function createCookie(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString()} else{expires=""}
document.cookie=name+"="+escape(value)+expires+"; path=/;"};
function readCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' '){c=c.substring(1,c.length)}
if(c.indexOf(nameEQ)==0){return unescape(c.substring(nameEQ.length,c.length))}}
return null};

function load() {
}

function GUnload() {
}