// detecting IE7 and IE6
function iesux() {
	if (navigator.appVersion.indexOf("MSIE")!=-1) {
		var temp=navigator.appVersion.split("MSIE");
		var version=parseFloat(temp[1]);
	}
	if (version < 7) return 6;
	else if (version < 8) return 7;
	else return 8;
}

// For the navigation dropdown menus and Related Content hovers:
// script to make IE to recognize hover state over list items
// borrowed from the "Suckerfish Dropdowns"
// (www.alistapart.com/articles/dropdowns)
startList = function() {
	if (Prototype.Browser.IE) {
		if (iesux() == 6) {
			// for dropdown nav
			if ($('nav')) {
				navRoot = $('nav');
				for (var i=0; i<navRoot.childNodes.length; i++) {
					node = navRoot.childNodes[i];
					if (node.nodeName=="LI") {
						node.onmouseover=function() {
							this.className+=" over";
						};
						node.onmouseout=function() {
							this.className=this.className.replace(" over", "");
						};
					}
				}
			}
			// for Related Content hovers and
			if ($('relatedArticles')) {
				rcRoot = $('relatedArticles');
				for (var i=0; i<rcRoot.childNodes.length; i++) {
					node = rcRoot.childNodes[i];
					if (node.nodeName=="LI") {
						node.onmouseover=function() {
							this.className+=" over";
						};
						node.onmouseout=function() {
							this.className=this.className.replace(" over", "");
						};
					}
				}
			}
			// for Cited By hovers
			if ($('citedBy')) {
				cbRoot = $('citedBy');
				for (var i=0; i<cbRoot.childNodes.length; i++) {
					node = cbRoot.childNodes[i];
					if (node.nodeName=="LI") {
						node.onmouseover=function() {
							this.className+=" over";
						};
						node.onmouseout=function() {
							this.className=this.className.replace(" over", "");
						};
					}
				}
			}
		}
	}
};
document.observe("dom:loaded", startList);

// SciFinder section population on page load
document.observe("dom:loaded", function() {
	if (!$('casSection')) return;
	var sfAuthorsLayer = $('sfAuthorsLayer');
	if (sfAuthorsLayer) {
		Event.observe(sfAuthorsLayer, 'submit', function(e) {
			if (!sfAuthorsLayer.lastName.value) {
				alert("Last name is required!");
				e.stop();
			}
		});
	}
	var sfTopicLayer = $('sfTopicLayer');
	if (sfTopicLayer) {
		Event.observe(sfTopicLayer, 'submit', function(e) {
			if (!sfTopicLayer.topic.value) {
				alert("Topic is required!");
				e.stop();
			}
		});
	}
	if ($('missingTopic')) toggleSFinterfaceOnLoad('sfTopic');
	if ($('missingLastName')) toggleSFinterfaceOnLoad('sfAuthors');
	if (location.search.indexOf("issuetypefield=yes") != -1) {
		var cb = $('issuetypefield');
		if (cb) {
			cb.checked = true;
			toggleDateRange(cb);
		}
	}
	var counterIdsAll = $('counterIdsAll');
	if (counterIdsAll) {
		var markAllcounterIds = function () {
			var a = counterIdsAll.form.counterIds;
			for (var i = 0; i < a.length; i++) { a[i].checked = counterIdsAll.checked; }
		};
		Event.observe(counterIdsAll, 'click', markAllcounterIds);
		Event.observe(counterIdsAll, 'change', markAllcounterIds);
	}
});

/* -------- start cookie scripts -------- */
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 var expires = "";
	document.cookie = name+"="+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 c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}
/* -------- end cookie scripts -------- */

// Same as above, but for the Related Content hovers
function ieRelated () {
if (document.all&&document.getElementById) {
navRoot = $('relatedArticles');
for (var i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
  }
  node.onmouseout=function() {
  this.className=this.className.replace(" over", "");
   };
   }
  }
 }
}

// 4 functions for hiding layers when clicking outside of them
	// A-Z Layer
	offClickAZ=function(event) {
		var target = Event.element(event);
		// Journal A-Z layer
		if (target==$('journalList') && $('pubsSelector').style.display!="block") counter++;
		if ($('pubsSelector') && $('pubsSelector').style.display=="block") {
			if (!target.descendantOf('pubsSelector') && target!=$('pubsSelector')) {
				toggleAZ();
				toggleAZ1();
				toggleAZ2();
				Event.stop(event);
			}
		}
	};
	
	
	
  offClickAZ1=function(event) {
		var target = Event.element(event);
		// Journal A-Z layer
		if (target==$('journalList1') && $('pubsSelector1').style.display!="block") counter++;
		if ($('pubsSelector1') && $('pubsSelector1').style.display=="block") {
			if (!target.descendantOf('pubsSelector1') && target!=$('pubsSelector1')) {
				toggleAZ();
				toggleAZ1();
				toggleAZ2();
				Event.stop(event);
			}
		}
	};	
	
	
	 offClickAZ2=function(event) {
		var target = Event.element(event);
		// Journal A-Z layer
		if (target==$('journalList2') && $('pubsSelector2').style.display!="block") counter++;
		if ($('pubsSelector2') && $('pubsSelector2').style.display=="block") {
			if (!target.descendantOf('pubsSelector2') && target!=$('pubsSelector2')) {
				toggleAZ();
				toggleAZ1();
				toggleAZ2();
				Event.stop(event);
			}
		}
	};	
	
		// In-line References
	offClickRef=function(event) {
		var target = Event.element(event);
		if (!target.descendantOf('openBalloon') && target!=$('openBalloon').parentNode.previousSiblings('a')[0]) {
			var sendThis=$('openBalloon').parentNode.previousSiblings('a')[0];
			showRef(sendThis);
		}
	};
	// Figure Viewer
	offClickFigViewer=function(event) {
		var target = Event.element(event);
		if ($('figureViewer-wrap').style.display!="none" && target!=$('figureViewer-wrap') && !target.descendantOf('figureViewer-wrap')) {
			showFigures(event);
			Event.stopObserving(document,"click",offClickFigViewer);
		}
	};
	// Article Anchor Menus
	offClickAnchors=function(event) {
		var target = Event.element(event);
		if (!target.descendantOf('openJumpMenu')) {
			showPulldown($('openJumpMenu').select('a')[0]);
		}
	};


// For clearing/repopulating the search input box,
// citation jump input boxes, and DOI input boxes
// Atypon version
function flipDefault(field) {
	if (!field.defaultValue) field.defaultValue = field.value;
	if (field.value == field.defaultValue) field.value = "";
	else if (field.value == "") field.value = field.defaultValue;
}

function checkInput(aType) {
	var inputs = (aType == 'advanced') ?
				 ['advSearchText', 'advTitle', 'advAuthor', 'advAbstract', 'advFigure'] :
				 ['searchText'];
	var valid = false;
	for (var i=0; i<inputs.length; i++) {
		var input = $(inputs[i]);
		valid |= input &&
				 (input.type == 'text') &&
				 (input.value.replace(/^\s+|\s+$/g,'').length > 0);
	}
	if (! valid) {
		alert("Enter search criteria.");
		return false;
	}
	return true;
}

function submitAdvSearch() {
	if (checkInput('advanced')) {
		document.advSearch.submit();
		return true;
	}
	return false;
}

// For showing/hiding the Journal List menu layer
function toggleAZ() {
	// first test for Explorer 6 and below to fix a bug in that crap browser
	var version=0;
	var needfix=0;
	if (Prototype.Browser.IE) {
		if (iesux() == 6) needfix=1;
	}

	// show or hide the Pubs Select layer
	var box=$('pubsSelector');
	var bg= new Array();
	bg[0]=$('header');
	bg[1]=$('mainBody');
	bg[2]=$('pageFooter-wrap');
	var n=0;

	if (box.style) {
		if (box.style.display=="none") {
			if (needfix==1) pubsSelectIEfix('hide');

			while (bg[n]) {
				bg[n].changeOpacity="0.50";
				bg[n].style.KHTMLOpacity="0.50";
				bg[n].style.opacity="0.50";
				n++;
			}
			box.style.display="block";
			// make it so that clicking off the layer hides the viewer
			Event.stopObserving(document,"click",offClickAZ);
			Event.stopObserving(document,"click",offClickAZ1); 
			Event.stopObserving(document,"click",offClickAZ2);
			 
		}
		else {
			if (needfix==1) pubsSelectIEfix('show');

			while (bg[n]) {
				bg[n].style.MozOpacity="1";
				bg[n].style.KHTMLOpacity="1";
				bg[n].style.opacity="1";
				n++;
			}
			box.style.display="none";
			Event.stopObserving(document,"click",offClickAZ);
			Event.stopObserving(document,"click",offClickAZ1); 
			Event.stopObserving(document,"click",offClickAZ2);
			 
		}
	}
}



function toggleAZ1() {
	// first test for Explorer 6 and below to fix a bug in that crap browser
	var version=0;
	var needfix=0;
	if (Prototype.Browser.IE) {
		if (iesux() == 6) needfix=1;
	}

	// show or hide the Pubs Select layer
	var box=$('pubsSelector1');
	var bg= new Array();
	bg[0]=$('header');
	bg[1]=$('mainBody');
	bg[2]=$('pageFooter-wrap');
	var n=0;

	if (box.style) {
		if (box.style.display=="none") {
			if (needfix==1) pubsSelectIEfix('hide');

			while (bg[n]) {
				bg[n].changeOpacity="0.50";
				bg[n].style.KHTMLOpacity="0.50";
				bg[n].style.opacity="0.50";
				n++;
			}
			box.style.display="block";
			// make it so that clicking off the layer hides the viewer
			 
			Event.stopObserving(document,"click",offClickAZ);
			Event.stopObserving(document,"click",offClickAZ1); 
			Event.stopObserving(document,"click",offClickAZ2);
		}
		else {
			if (needfix==1) pubsSelectIEfix('show');

			while (bg[n]) {
				bg[n].style.MozOpacity="1";
				bg[n].style.KHTMLOpacity="1";
				bg[n].style.opacity="1";
				n++;
			}
			box.style.display="none";
			 
			Event.stopObserving(document,"click",offClickAZ);
			Event.stopObserving(document,"click",offClickAZ1); 
			Event.stopObserving(document,"click",offClickAZ2);
		}
	}
}






function toggleAZ2() {
	// first test for Explorer 6 and below to fix a bug in that crap browser
	var version=0;
	var needfix=0;
	if (Prototype.Browser.IE) {
		if (iesux() == 6) needfix=1;
	}

	// show or hide the Pubs Select layer
	var box=$('pubsSelector2');
	var bg= new Array();
	bg[0]=$('header');
	bg[1]=$('mainBody');
	bg[2]=$('pageFooter-wrap');
	var n=0;

	if (box.style) {
		if (box.style.display=="none") {
			if (needfix==1) pubsSelectIEfix('hide');

			while (bg[n]) {
				bg[n].changeOpacity="0.50";
				bg[n].style.KHTMLOpacity="0.50";
				bg[n].style.opacity="0.50";
				n++;
			}
			box.style.display="block";
			// make it so that clicking off the layer hides the viewer
			 
			Event.stopObserving(document,"click",offClickAZ);
			Event.stopObserving(document,"click",offClickAZ1); 
			Event.stopObserving(document,"click",offClickAZ2);
		}
		else {
			if (needfix==1) pubsSelectIEfix('show');

			while (bg[n]) {
				bg[n].style.MozOpacity="1";
				bg[n].style.KHTMLOpacity="1";
				bg[n].style.opacity="1";
				n++;
			}
			box.style.display="none";
			Event.stopObserving(document,"click",offClickAZ);
			Event.stopObserving(document,"click",offClickAZ1); 
			Event.stopObserving(document,"click",offClickAZ2);
		}
	}
}
// companion script to make pubsSelect() work in Explorer 6 and below
// without having the form select boxes appear through the Pubs Select layer
function pubsSelectIEfix(hideOrShow) {
	// for Browse By Issue boxes on journal-specific pages
	if ($('inDecade')) {
		var hideBrowse1=$('inDecade');
		var hideBrowse2=$('inVolume');
		var hideBrowse3=$('inIssue');
		if (hideOrShow=="hide") {
			hideBrowse1.style.visibility="hidden";
			hideBrowse2.style.visibility="hidden";
			hideBrowse3.style.visibility="hidden";
		}
		else {
			hideBrowse1.style.visibility="visible";
			hideBrowse2.style.visibility="visible";
			hideBrowse3.style.visibility="visible";
		}
	}
	// for Quick Search pulldowns
	if ($('qs')) {
		var qs1=$('qsSearchArea');
		if ($('qsProduct')) var qs2=$('qsProduct');
		if (hideOrShow=="hide") {
			qs1.style.visibility="hidden";
			if (qs2) qs2.style.visibility="hidden";
		}
		else {
			qs1.style.visibility="visible";
			if (qs2) qs2.style.visibility="visible";
		}
	}
	// for journal selector on ARRC pages
	if ($('arrcJournalInfo')) {
		var arrc=$('arrcJournalInfo');
		if (hideOrShow=="hide") {
			arrc.style.visibility="hidden";
		}
		else arrc.style.visibility="visible";
	}
	// for account selector on Lib. Admin. pages
	if ($('libAccount')) {
		var account=$('libAccount');
		if (hideOrShow=="hide") {
			account.style.visibility="hidden";
		}
		else account.style.visibility="visible";
	}
	// for month/year navigation on Online News Archive and newsletters
	if ($('monthYearNav')) {
		var account=$('monthYearNav');
		if (hideOrShow=="hide") {
			account.style.visibility="hidden";
		}
		else account.style.visibility="visible";
	}
}

// Another pair of scripts to fix IE's problem with select boxes showing through layers
// This one is for the Author Index page
function fixAI4IE(state) {
	if (Prototype.Browser.IE) {
		if (iesux() == 6) {
			if ($('aiVolJump')) {
				var form=$('aiVolJump');
				var select1=form.getElementsByTagName('select')[0].style;
				var select2=form.getElementsByTagName('select')[1].style;
				if (state=="on") {
					select1.visibility="hidden";
					select2.visibility="hidden";
				}
				else {
					select1.visibility="visible";
					select2.visibility="visible";
				}
			}
		}
	}
}
// This one is only for the Online News Archive
function fixArchive4IE(state) {
	if (Prototype.Browser.IE) {
		if (iesux() == 6) {
			if ($('newsArchiveNav')) {
				var form=$('newsArchiveNav');
				var select1=form.getElementsByTagName('select')[0].style;
				var select2=form.getElementsByTagName('select')[1].style;
				if (state=="on") {
					select1.visibility="hidden";
					select2.visibility="hidden";
				}
				else {
					select1.visibility="visible";
					select2.visibility="visible";
				}
			}
		}
	}
}

// For toggling the article lists on the journal home pages
function toggleArticleList(focus) {
	var focusList=focus+"Articles";
	var focusTab=focus+"Tab";

	var list = new Array($('justAcceptedArticles'),$('justPublishedArticles'),$('currentIssueArticles'),$('mostReadArticles'),$('mostCitedArticles'));
	var tab = new Array($('justAcceptedTab'),$('justPublishedTab'),$('currentIssueTab'),$('mostReadTab'),$('mostCitedTab'));
	focusList=$(focusList);
	focusTab=$(focusTab);

	// first, hide all lists
	list[0].style.display="none";
	list[1].style.display="none";
	list[2].style.display="none";
	list[3].style.display="none";
	list[4].style.display="none";

	// second, show the one that was clicked
	focusList.style.display="block";

	// third, put all the tab backgrounds into the neutral position;
	tab[0].style.backgroundPosition="-4px -4px";
	tab[1].style.backgroundPosition="-99px -4px";
	tab[2].style.backgroundPosition="-194px -4px";
	tab[3].style.backgroundPosition="-289px -4px";
	tab[4].style.backgroundPosition="-384px -4px";

	// fourth, put the focused tab background into the active position
	if (focus=="justAccepted") {
		focusTab.style.backgroundPosition="-4px -29px";
	}
	else if (focus=="justPublished") {
		focusTab.style.backgroundPosition="-99px -29px";
	}
	else if (focus=="currentIssue") {
		focusTab.style.backgroundPosition="-194px -29px";
	}
	else if (focus=="mostRead") {
		focusTab.style.backgroundPosition="-289px -29px";
	}
	else {
		focusTab.style.backgroundPosition="-384px -29px";
	}
	//added by Atypon
	setRange(focusList);
	prepareThumbFromTab(focusList);
}

// To update the Select All checkbox
function updateSelectAllBox(checkState,form) {
	var oneOrTwo=form.selectAll.length;
	if (oneOrTwo==2) {
		form.selectAll[0].checked=checkState;
		form.selectAll[1].checked=checkState;
	}
	else form.selectAll.checked=checkState;
}

// For selecting/deselecting articles
function selectDeselect(box) {
	var form=box.form;
	var checkState=false;
	var n = 0;
	if (box.checked==true) checkState=true;

	if (form.doi[1]) { // if there is more than one article on the page
		while (form.doi[n]) {
			form.doi[n].checked=checkState;
			n++;
		}
		updateSelectAllBox(checkState,form)
	}
	else form.doi.checked=checkState; // if there's only one article on the page (search result or asap page)
}

function submitArticles(anElement, action) {
	var aForm = $(anElement).up('form');
	submitMultiArticles(aForm, action, false);
}

// For checking if all of the checkboxes are checked or not
function evalAll(box) {
	var form=box.form;
	var checked=0;
	var max=form.doi.length;
	for (var count=0; count < max; count++) {
		if (eval("form.doi[" + count + "].checked") == true) {
			checked++;
		}
	}
	if (checked==max) updateSelectAllBox(true,form);
	else updateSelectAllBox(false,form);
}

function updateFigImg(doiFigure, index, imgTag) {
	var isMedium = index== 0 && doiFigure.isTocFigure;
	imgTag.src = doiFigure.path + '/images/' + (isMedium ? 'medium/' : 'small/') + doiFigure.images[index];
	$(imgTag)[isMedium ? 'addClassName' : 'removeClassName']('tocGraphic');
}

// For toggling the Journal View on the Pubs Home Page
function changeView(id) {
	var show=id+"View";
	var highlight=id+"Link";

	var block1=$('azView');
	var block2=$('catView');
	show=$(show);
	var link1=$('azLink');
	var link2=$('catLink');
	highlight=$(highlight);

	// first, hide both views
	block1.style.display="none";
	block2.style.display="none";

	// second, show the one that was clicked
	show.style.display="block";

	// third, set both links to the default appearance
	link1.style.fontWeight="normal";
	link1.style.background="transparent";
	link1.style.color="#369";
	link1.style.border="0";
	link2.style.fontWeight="normal";
	link2.style.background="transparent";
	link2.style.color="#369";
	link2.style.border="0";

	// fourth, highlight the link that was used
	highlight.style.fontWeight="bold";
	highlight.style.background="#eee";
	highlight.style.color="#000";
	highlight.style.border="solid 1px #ccc";
}

// Article template pulldown menus
// Also used on Cover Catalog sorted by volume
function showPulldown(button) {
	var block;
	var list;

	// for cover art gallery
	if ($('coverVol')) {
		block=$('coverVol');
		button=button.getElementsByTagName('a')[0];
		list=button.parentNode.getElementsByTagName('ul')[0];
		if (list.style.display == "none") {
			Effect.BlindDown(list, {duration:0.3});
			button.style.backgroundPosition="0 -20px";
		}
		else {
			block.style.zIndex="1";
			Effect.BlindUp(list, {duration:0.3});
			button.style.backgroundPosition="0 0";
		}
	}

	// for full text html template
	else {
		block=button.parentNode.parentNode; // ul.anchors
		list=button.parentNode.getElementsByTagName('ul')[0];
		if (list.style.display == "none") {
			block.style.zIndex="9000";
			Effect.BlindDown(list, {duration:0.3});
			button.style.backgroundPosition="0 -20px";
			$(block).writeAttribute("id","openJumpMenu");
			Event.observe(document,"click",offClickAnchors);
		}
		else {
			block.style.zIndex="1";
			Effect.BlindUp(list, {duration:0.3});
			button.style.backgroundPosition="0 0";
			$(block).writeAttribute("id","");
			Event.stopObserving(document,"click",offClickAnchors);
		}
	}
}

function hidePulldown(anchor) {
	var button=anchor.parentNode.parentNode.parentNode.getElementsByTagName('a')[0];
	showPulldown(button);
}

// Article template reference viewer
// note: needed to weed out Opera because it doesn't display properly
function showRef(ref, ids) {
	initReferencesBaloon(ref, ids);	 // Added by Atypon
	var browserName=navigator.appName;
	if (browserName != "Opera" || /\d+/.exec(navigator.appVersion)[0] >= 9) {
		var balloon=$(ref).next().down();
		if (balloon && balloon.style) { // Atypon: degrade gracefully when baloon is not found
			if (balloon.style.display != "inline") {
				//  hideRef is calling showRef - need to check if is different before is hidden
				var isDifferent = !window.openedReferenceBalloon || window.openedReferenceBalloon.innerHTML != balloon.innerHTML;
				if (window.openedReferenceBalloon) hideRef(window.openedReferenceBalloon);
				if (isDifferent) {
					balloon.style.display = "inline";
					window.openedReferenceBalloon = balloon;
					balloon.writeAttribute("id","openBalloon");
				}
				Event.observe.defer(document,"click",offClickRef);

			}
			else {
				balloon.style.display="none";
				window.openedReferenceBalloon = false;
				balloon.writeAttribute("id","");
				Event.stopObserving(document,"click",offClickRef);
			}
			return;
		}
	}
	parent.location="#references";
}
function hideRef(ref) {
	ref=$(ref).up('.ref').previous();
	showRef(ref);
}

// Sign In Page
function preRegMessage(registrationPage) {
	var r=confirm("To register on this site, you must create an ACS ID on the ACS Society website (www.acs.org). After completing your registration, you will be returned back to the page you were viewing on the ACS Publications website (pubs.acs.org).");
		if (r==true) {
			parent.location=registrationPage;
		}
	else {
		return false;
	}
}

// Article template permalink viewer
function showPermalink(doi) {
	doi=doi.parentNode.getElementsByTagName('span')[0];
	if (doi.style.display == "none") {
		Effect.BlindDown(doi, {duration: 0.3});
	}
	else Effect.BlindUp(doi, {duration: 0.3});
}
function hidePermalink(doi) {
	doi=doi.parentNode.parentNode.getElementsByTagName('a')[0];
	showPermalink(doi);
}

// Function added by Atypon
function toggleSFinterfaceOnLoad(id) {
	Event.observe(window, 'load', function() {
		var radio = $(id);
		radio.checked = true;
		toggleSFinterface(radio);
	});
}
// SciFinder Explore Section
function toggleSFinterface(target) {
	target=$(target);
	$('sfArtAuthorsLayer').style.display="none";
	$('sfAuthorsLayer').style.display="none";
	$('sfTopicLayer').style.display="none";
	if (target==$('sfArtAuthors')) {
		$('sfArtAuthorsLayer').style.display="block";
		$('sfArtAuthorsSelect').focus();
	}
	else if (target==$('sfAuthors')) {
		$('sfAuthorsLayer').style.display="block";
		$('sfAuthorLast').focus();
	}
	else {
		$('sfTopicLayer').style.display="block";
		$('sfTopicInput').focus();
	}
}

// Article template figure viewer
function showFigures(e) {
	//added by Atypon
	var n=0;
	if (!e)	var e = window.event;
	initViewer(e);  /* Atypon change */
	var viewer=$('figureViewer-wrap');
	if (!viewer) return; // It may take some time till document gets ready
	if (viewer.style.display != '') {
		bg= new Array(); /* Atypon change */
		bg[0]=$('header');
		bg[1]=$('mainBody');
		bg[2]=$('pageFooter-wrap');
		var posY=0;

		if (e.pageY) {
			posY = e.pageY;
		}
		else if (e.clientY) {
			posY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}

		while (bg[n]) {
			bg[n].style.MozOpacity="0.70";
			bg[n].style.KHTMLOpacity="0.70";
			bg[n].style.opacity="0.70";
			n++;
		}
		Effect.Appear('figureViewer-wrap', {duration:0.5});
		posY=posY-100; // offset from mouse position
		viewer.style.top=posY+"px";
		new Draggable('figureViewer-wrap',{starteffect: null, endeffect: null});

		// clicking off the viewer hides the viewer
		Event.observe(document,"click",offClickFigViewer);
	}
	else {
		while (bg[n]) {
			bg[n].style.MozOpacity="1";
			bg[n].style.KHTMLOpacity="1";
			bg[n].style.opacity="1";
			n++;
		}
		Effect.Fade('figureViewer-wrap', {duration:0.5});
		Event.stopObserving(document,"click",offClickFigViewer);
	}
}


// Search Page: Journal Filter Interface functions
function togglejFilter(event) {
	var target=$('jFilterInterface');
	if (!event)	var event = window.event;
	if ($(target).style.display == "none") {
		if (!$(target).hasClassName('sorted')) {
			// count the number of titles
			var n=1; // start at 1 because the first div (0) is not a title
			while ($(target).getElementsByTagName('div')[n]) {
				n++;
			}
			var titles=n-1; // account for the last n++ in the loop

			var n=1;
			var title = new Array();
			// load each div into an array
			while (target.getElementsByTagName('div')[n]) {
				title[n-1]="<div>"+target.getElementsByTagName('div')[n].innerHTML+"</div>";
				n++;
			}
			var col2start=Math.round((n-1)/2); // determines the first title to list in second column
			// generate the HTML for the first column
			var col1="";
			for (var i=0; i<col2start; i++) {
				col1=col1+title[i];
			}
			col1="<div>"+col1+"</div>";
			// generate the HTML for the second column
			var col2="";
			for (var i=col2start; i<n-1; i++) {
				col2=col2+title[i];
			}
			col2="<div>"+col2+"</div>";
			// add class to jFilterInterface to prevent sorting after the first call
			$(target).addClassName('sorted');
			// spit out the new HTML
			var topHTML='<a onclick="journalFilter(\'cancel\'); return false;" class="close" href="#">Cancel</a> <h4>Journal and Book Series Filter</h4> <p>Select the journals and book series you would like to search within and click the "Update" button.<br/> To close this window without making changes, click "Cancel" in the top right corner.</p> <div class="buttons"> <input type="button" onclick="journalFilter(\'update\');" value="Update" id="save" /> <a href="JavaScript:changeAll(\'select\')">Select All</a> | <a href="JavaScript:changeAll(\'deselect\')">Deselect All</a></div>';
			$(target).innerHTML=topHTML + col1 + col2;
		}

		// display the hidden layer
		var posY=Event.pointerY(event);
		target.style.top=posY-250+"px";
		Effect.Appear(target, {duration:0.3});
	}
	else {
		Effect.Fade(target, {duration:0.3});
	}
}
function journalFilter(action, skipToggle) {
	if (action=="cancel") {
		togglejFilter();
	}
	else {
		var max=document.advSearch.publication.length;
		var coden=new Array();
		var list=$('selJournals');
		var checked=0;
		for (var count=0; count < max; count++) {
			if (eval("document.advSearch.publication[" + count + "].checked") == true) {
				coden[checked]=document.advSearch.publication[count].value;
				checked++;
			}
		}
		if (checked == 0 || checked==max) {
			list.innerHTML="<li>All ACS Journals and Book Series</li>";
			if (!skipToggle) {
				togglejFilter();
			}
		}
		else {
			var jList="";
			var n=0;
			while (coden[n]) {
				coden[n]=decodeCoden(coden[n]);
				jList=jList + "<li>" + coden[n] + "</li>";
				n++;
			}
			list.innerHTML=jList;
		}
		new Effect.Highlight(list, {duration: 2.5});
		if (!skipToggle) {
			togglejFilter();
		}
	}
}

function changeAll(toggle) {
	var boxGroup=document.advSearch.publication;
	updateChecks(boxGroup,toggle);
}

function updateChecks(boxGroup,toggle) {
	var max=boxGroup.length;
	if (toggle=="select") {
		for (var count=0; count < max; count++) {
			boxGroup[count].checked=true;
		}
	}
	else {
		for (var count=0; count < max; count++) {
			boxGroup[count].checked=false;
		}
	}
}

Event.observe(window, "load", function() {
	var f = $('searchName');
	if (f) Event.observe(f, 'keydown', function(e) {
		if (Event.KEY_RETURN == (e.which || e.keyCode)) {
			Event.stop(e);
			saveSearch('step2');
		}
	})
});
function saveSearch(action) {
	var button1=$('saveit');
	var button2=$('finalize');
	var link=$('viewSaved');
	var layer1=$('saveSearchA');
	var layer2=$('saveSearchB');
	var layer3=$('saveSearchC');
	var layer4=$('saveSearchD');
	if (action=="step2") {
		Effect.Fade(button1);
		Effect.Appear(button2);
		Effect.Fade(link);
		Effect.BlindDown(layer2);
	}
	else if (action=="cancel") {
		Effect.BlindUp(layer2);
		Effect.Appear(button1);
		Effect.Fade(button2);
		Effect.Appear(link);
	}
	else if (action=="saving") { // atypon change
		layer1.style.display="none";
		layer2.style.display="none";
		Effect.Appear(layer3);
	}
	else if (action=="finalize") {
		layer1.style.display="none";
		layer2.style.display="none";
		layer3.style.display="none";
		Effect.Appear(layer4); // atypon change
	}
	else return false;
}

function showSearchTips() {
	var tips=$('searchTipsLayer');
	var link=$('searchTipsLink');
	var needfix=0;
	var results=$('results');
	var pulldown1=results.getElementsByTagName('form')[0];
	var pulldown2=results.getElementsByTagName('form')[1];

	if (Prototype.Browser.IE) {
		if (iesux() == 6) needfix=1;
	}


	if (tips.style.display=="none") {
		if (needfix==1) {
			pulldown1.style.display="none";
			pulldown2.style.display="none";
		}
	Effect.Appear(tips);
	link.innerHTML="Hide Search Tips";
	}

	else {
		if (needfix==1) {
			pulldown1.style.display="block";
			pulldown2.style.display="block";
		}
	Effect.Fade(tips);
	link.innerHTML="Show Search Tips";
	}
}

function showIssues(link, jCode, volume) {
	var link = $(link);
	link.up('ul').toggleClassName('closed');
	if (!link.enteredOnce) {
		link.enteredOnce = true;
		if (!link.next('ul')) {
			var li = link.up('li');
			if (!li.innerHTMLBackup) li.innerHTMLBackup = li.innerHTML;
			li.innerHTML+="<img src='/templates/jsp/_style2/_achs/images/loading.gif'/>";
			new Ajax.Request('/action/showPage?page=/widgets/volume_ul.jsp&journalCode='+jCode+"&volume="+volume, {
				onSuccess: function(transport) {
					li.innerHTML = li.innerHTMLBackup + transport.responseText;
				}
			});
		}
	}
}

// Online News Archive
function showMonth(anchor,month) {
	var months = new Array();
	months[0]="all";
	months[1]="jan";
	months[2]="feb";
	months[3]="mar";
	months[4]="apr";
	months[5]="may";
	months[6]="jun";
	months[7]="jul";
	months[8]="aug";
	months[9]="sep";
	months[10]="oct";
	months[11]="nov";
	months[12]="dec";

	// hide all layers
	for (var x=1; x<13; x++) {
		var hide=document.getElementById(months[x]).style;
		hide.display="none";
	}

	// reset all anchors
	for (var x=0; x<13; x++) {
		var change=anchor.parentNode.parentNode.getElementsByTagName('a')[x].style;
		change.backgroundColor="#eee";
		change.color="#369";
	}

	// show the appropriate layer(s)
	if (month=="all") {
		for (var x=1; x<13; x++) {
			var show=document.getElementById(months[x]);
			Effect.Appear(show);
		}
	}
	else {
		month=document.getElementById(month);
		Effect.Appear(month);
	}
	// highlight the appropriate anchor
	anchor.style.backgroundColor="#369";
	anchor.style.color="#fff";
}

// Email Registration
function enableRadio(checkbox, radio1, radio2) {
	checkbox=document.getElementById(checkbox);
	radio1=document.getElementById(radio1);
	radio2=document.getElementById(radio2);
	if (checkbox.checked==true) {
		radio1.disabled=false;
		radio2.disabled=false;
	}
	else {
		radio1.disabled=true;
		radio2.disabled=true;
	}
}

// Electronic Galley Proof
function enableTextarea(textAreaID) {
	radioSet=document.proofForm.readyState;
	textbox=$(textAreaID);
	for (var i=0; i < radioSet.length; i++) {
		if (radioSet[i].checked) {
			var radioValue = radioSet[i].value;
		}
	}
	textbox.disabled = radioValue != "nobutton";
}

// Profile: Saved Searches
function toggleCriteria(button) {
	criteria=button.parentNode.parentNode.getElementsByTagName('div')[1];
	if (criteria.style.display=="none") {
		Effect.BlindDown(criteria);
		button.innerHTML="&uarr; Hide Criteria";
	}
	else {
		Effect.BlindUp(criteria);
		button.innerHTML="&darr; Show Criteria";
	}
}

/* Atypon added */
function initViewer(e) {
	if (!window.figureViewer) return false;
	if ($('figureViewer-wrap') && $('figureViewer-wrap').style.display == '') return false;

	var figures = window.figureViewer.figures;

	/* clear up figures that were not rendered */
	for (var i = figures.length - 1; i >= 0; i--) {
		var figureMeta = figures[i];
		if (!figureMeta || !$(figureMeta.i)) figures.splice(i, 1);
	}
	if (figures.length == 0) {
		window.figureViewer = null;
		return false;
	}

	var fvw = $('figureViewer-wrap');
	if (!fvw) {
		var c = $('container');
		if (c) {
			fvw = document.createElement("div");
			fvw.id='figureViewer-wrap';
			fvw.style.display='none';
			c.appendChild(fvw);
			fvw.innerHTML =
				'<div id="figureViewer">\
					<div id="figureViewerNav">\
						<a title="Close Figure Viewer" href="#" onclick="showFigures(event); return false;" class="close">Close</a>\
						<div class="figureNav">\
							<a class="prev" title="Previous Figure" href="#" class="disabled"></a>\
							<span>Figure <span class="index">1</span> of ' + figures.length + '</span>\
							<a class="next" title="Next Figure" href="#" class="disabled"></a>\
						</div>\
					</div>\
					<div id="figureCanvas">\
						<div id="figTools">\
						</div>\
						<div class="figBox">\
						</div>\
						<div class="caption">&nbsp;\
						</div>\
					</div>\
				</div>\
				<div id="figureViewer-footer">\
					<img alt="" src="/templates/jsp/_style2/_achs/images/figureViewer-bg3.gif"/>\
				</div>';
			fvw = $(fvw);
		}
	}

	var index = 0;
	var figureElement = Event.findElement(e, ".figure");
	if (figureElement && figureElement.id) {
		var figureId = figureElement.id;
		while (index < figures.length && figures[index].i != figureId) index++;
	}
	showImage(index);
}

function showImage(index) {
	var figures = window.figureViewer.figures;
	var figureMeta = figures[index];
	if (!figureMeta) figureMeta = figures[index=0];
	var graphics = figureMeta.g;
	var figureElement = $(figureMeta.i);

	var fvw = $('figureViewer-wrap');

	/* image and caption */
	var html = "";
	for (var i = 0; i < graphics.length; i++) {
		html += '<img alt="Figure" src="' + window.figureViewer.path + '/images/medium/' + graphics[i].m + '"/>';
	}
	fvw.down(".figBox").innerHTML = html;
	var captionElement = figureElement.down(".caption");
	fvw.down(".caption").innerHTML = captionElement ? captionElement.innerHTML : "";

	/* navigation */
	var pLink = fvw.down('.prev');
	if (index == 0) {
		pLink.addClassName("disabled");
		pLink.href = "#"
	} else {
		pLink.removeClassName("disabled");
		pLink.href = "JavaScript:showImage(" + (index - 1) + ")";
	}

	index++;
	var nLink = fvw.down('.next');
	if (index == figures.length) {
		nLink.addClassName("disabled");
		nLink.href = "#"
	} else {
		nLink.removeClassName("disabled");
		nLink.href = "JavaScript:showImage(" + index + ")";
	}

	fvw.down('.index').innerHTML = index;

	/* figure tools */
	var ftHtml = '';

	if (figureMeta.weo) {
		for (var i = 0; i < figureMeta.weo.length; i++) {
			var weo = figureMeta.weo[i];
			if (weo && weo.h) {
				ftHtml += '<div class="weo"><a title="View this Web Enhanced Object'
				if (weo.t) { ftHtml += ': ' + weo.t; }
				ftHtml += '" href="' + weo.h + '" target="_blank"><span>Web Enhanced Object</span></a></div>';
			}
		}
	}


	html = '';
	for (var i = 0; i < graphics.length; i++) {
		if (graphics[i].l) {
			if (html) html += '<br />'; // is not first link
			html += '<a href="' + window.figureViewer.path + '/images/large/' + graphics[i].l + '"><span>High Resolution Image</span></a>';
		}
	}
	if (html) {
		ftHtml += '<div class="highRes">' + html + '</div>';

		ftHtml += '<div class="ppt"><a title="Download MS PowerPoint Slide" href="/action/downloadFigures?doi=' + window.figureViewer.doi + '&id=' + figureMeta.i + '">\
				  <span>PowerPoint Slide</span>\
			   </a></div>';
	}

	fvw.down('#figTools').innerHTML = ftHtml;
}

function requestFigures(url) {
	requestFigures('/action/showFullPopup?id=figureInfo&doi=10.1021/ac060120a');
	showLoading();

	new Ajax.Request(url, {
		onSuccess: function(transport) {
			alert(transport.responseText);
			displayFigureBrowser();
		}
	});
}

function showLoading() {
	alert("Loading");
}
function displayFigureBrowser() {
	alert("Loaded");
}
function popRef2(ids) {
}

function initReferencesBaloon(link, ids) {
	if (!ids) return;
	link = $(link);
	var bv = link.next();
	if (!bv || bv.tagName.toLowerCase()!= 'span' || bv.className!='ref') {
		if (typeof ids == "string") ids = ids.split(' ');
		var content = "";
		for (var i = 0; i < ids.length; i++) {
			var refLabel = $(ids[i]).down('.refLabel');
			if (refLabel && ids.length == 1){
				//remove label only for display purposes.
				var label = refLabel.innerHTML;
				refLabel.innerHTML="";
				content += '<span>' + $(ids[i]).innerHTML + "</span>";
				//insert it back after display incase the same reference is used with another one (multiple references should display labels)
				refLabel.innerHTML=label;
			}else{
				content += '<span>' + $(ids[i]).innerHTML + "</span>";
			}
		}
		link.insert({after: '<span class="ref"><span class="balloon-wrap"><span class="balloon"><a title="Hide Reference Information" onclick="hideRef(this); return false;" href="#" class="close"></a>' + content + '<a class="refLink" title="View References" onclick="hideRef(this);" href="#references">View Full Reference List</a></span></span></span>'});
	}
}
//atypon method
function setupNextPrev(figureNav, doiFigure, index){
	var currentImages = doiFigure.images;
	var size = currentImages.length;
	if (size==1){
		$(figureNav).addClassName("disabled");//by default
		figureNav.style.display="none";
		return;
	};
	figureNav.style.display="block";
	var doi = doiFigure.doi;
	var nLink = $(figureNav).select('.next')[0];
	var prevLink = $(figureNav).select('.prev')[0];
	if (index == size-1){//index is last, disable next and set previous
		nLink.addClassName("disabled");
		prevLink.removeClassName("disabled");
		prevLink.stopObserving('click',prevEvent);
		var prevEvent = function(e){changeImage(this,index-1,doi); Event.stop(e)}
		prevLink.observe('click', prevEvent);
	}else if(index == 0){ //index is first, disable prev and set next
		prevLink.addClassName("disabled");
		nLink.removeClassName("disabled");
		nLink.stopObserving('click',nextEvent);
		var nextEvent = function(e){changeImage(this,index+1,doi); Event.stop(e)};
		nLink.observe('click', nextEvent)
	}else{
		prevLink.removeClassName("disabled");
		prevLink.stopObserving('click',prevEvent);
		var prevEvent = function(e){changeImage(this,index-1,doi); Event.stop(e)};
		prevLink.observe('click',prevEvent)
		nLink.removeClassName("disabled");
		nLink.stopObserving('click',nextEvent);
		var nextEvent = function(e){changeImage(this,index+1,doi); Event.stop(e)};
		nLink.observe('click',nextEvent);
	 }
	figureNav.getElementsByTagName('span')[0].innerHTML='Figure ' + eval(index+1) + ' of ' + size;
}

function changeImage(navLink, index, doi){
	var figureTray = navLink.parentNode.parentNode.parentNode;
	var imgTag = $(figureTray).select('img')[0];
	var doiFigure = getDoiFigures(doi);
	if (!doiFigure) return;
	imgTag.style.border="0";
	imgTag.src="/templates/jsp/_style2/_achs/images/loading.gif";
	setTimeout(function() {updateFigImg(doiFigure, index, imgTag); imgTag.style.border="1px solid #ccc"; }, 500);
	var figureNav = figureTray.select('.figureNav')[0];
	setupNextPrev(figureNav, doiFigure, index);
}
function getDoiIndex(doi) {
	var figures = window.figureViewer;
	if (!figures) return -1;
	var max = figures.length;
	for (var count=0; count < max; count++) {
		if (figures[count].doi == doi){
		   return count;
		}
	}
	return -1;
}
function getDoiFigures(doi) {
	var doiFigure;
	var figures = window.figureViewer;
	if (!figures) return;
	var max = figures.length;
	for (var count=0; count < max; count++) {
		if (figures[count].doi == doi){
		   return doiFigure=figures[count];
		}
	}
}

function addFigure(doi, path, images, isTocFigure) {
	var figureViewer = window.figureViewer;
	var figure = {doi:doi,path:path,images:[images]};
	if (isTocFigure) figure.isTocFigure = true;
	var doiIndex = getDoiIndex(doi);
	if (!figureViewer){
		figureViewer = new Array();
		figureViewer[0]=figure;
	}else if(doiIndex > -1){
		var doiImages = figureViewer[doiIndex].images;
		doiImages[doiImages.length] = images;
		figureViewer[doiIndex].images = doiImages;
	}else{
		var size = figureViewer.length;
		figureViewer[size]=figure;
	}
	window.figureViewer = figureViewer;
}

function createIssueNav(tocNav) {
	var subjects = $$('div.subject');
	if (!subjects || subjects.length < 2) return;
	var tocHtml =  "<h4>In this issue:</h4> <ul>";
	for (var count = 0; count < subjects.length; count++) {
	   subject = $(subjects[count]);
	   tocHtml += '<li><a href="#' + subject.parentNode.id +'">' + subject.innerHTML + '</a></li>'
	}
	tocHtml += '</ul>';
	tocNav.innerHTML=tocHtml;
}

function openMultiTrays(button) {
	if (!button) return;
	var form = $(button).up('form');
	button=button.style;
	var body = $$('body')[0];

	// user opts to show thumbnails
	if (button.backgroundPosition != "0px -18px") {
		createCookie('thumbs','show',0); // set cookie to always show thumbnails
		body.removeClassName('noThumbs');
		// create global variables if not already created
		if (!window.formArticles) {
			formArticles = form.getInputs('checkbox','doi');
			allFormArticles = formArticles.length;
			loopedArts = new Array(allFormArticles);
		}
		Event.observe(window,'scroll',loadThumbnailsA);
		loadThumbnailsB();
		button.backgroundPosition = "0px -18px";
	}
	// user opts to hide thumbnails
	else {
		createCookie('thumbs','hide',0); // set cookie to always hide thumbnails
		body.addClassName('noThumbs');
		Event.stopObserving(window,'scroll',loadThumbnailsA);
		button.backgroundPosition = "0px 0px";
	}
}

function loadThumbnailsA() {
	var initBottom = document.viewport.getHeight() + document.viewport.getScrollOffsets()[1] + 700;
	// check if still scrolling before starting the load process (improves IE scrolling performance)
	var t = setTimeout(function(){loadThumbnailsB(initBottom); initBottom = null;},100); // parameter set to null to prevent IE memory leak
}

function loadThumbnailsB(initBottom) {
	var top = document.viewport.getScrollOffsets()[1];
	var wHeight = document.viewport.getHeight();
	var bottom = top + wHeight + 700;
	if (initBottom && bottom != initBottom) return; // stop if user is still scrolling
	Event.stopObserving(window,'scroll',loadThumbnailsA);
	var wrap, tray, figBox, nav, img, doi, doiFigure;
	// show thumbnails for articles that are above the bottom threshold
	for (var count=0; count < allFormArticles; count++) {
		if (formArticles[count].cumulativeOffset()[1] < top) continue; // skip loop if the article is above the viewport
		if (bottom < formArticles[count].cumulativeOffset()[1]) break; // stop loop if the article is below the bottom threshold
		if (loopedArts[count] == 1) continue; // stop if the article has already been through the loop
		loopedArts[count] = 1; // set to 1 so that we can ignore this article if it gets put into the loop again
		wrap = formArticles[count].parentNode.parentNode;
		doi = formArticles[count].value;
		doiFigure = getDoiFigures(doi);
		if (doiFigure) {
			tray = $(wrap).select('div.figureTray')[0];
			tray.style.display="block";
			figBox = $(tray).select('div.figureBox')[0];
			figBox.style.display = "block";
			img = $(figBox).select('img')[0];
			updateFigImg(doiFigure, 0, img);
			nav = $(tray).select('div.figureNav')[0];
			setupNextPrev(nav, doiFigure, 0);
		}
	}
	Event.observe(window,'scroll',loadThumbnailsA);
}

function prepareThumFromForm(form) {
	if (!form) return;
	if (!form.doi) return;
	if (readCookie('thumbs') == "hide") return false; // stop if user has opted to hide thumbnails
	form.select('a.showThumbs')[0].style.backgroundPosition="0px -18px"; // update Show/Hide Thumbnails button

	// create global variables
	formArticles = form.getInputs('checkbox','doi');
	allFormArticles = formArticles.length;
	loopedArts = new Array(allFormArticles);

	loadThumbnailsB();
	if ($('tocNav')) createIssueNav($('tocNav')); // for issue TOCs
	Event.observe(window,'scroll',loadThumbnailsA);
}
function prepareThumbFromTab(tab) {
	var form = $(tab).down('form');
	prepareThumFromForm(form);
}
function prepareThumbnails() {
	var form = $('tocArticles');
	prepareThumFromForm(form);
}
document.observe("dom:loaded", prepareThumbnails);

// Atypon JS
function hideAndShow(hideThis, showThis, cssClassForShown, hideTab, showTab) {
	hideThis = $(hideThis);
	showThis = $(showThis);
	if (hideThis && hideThis.style.display != 'none') {
		if (cssClassForShown) {
			$(hideTab).removeClassName(cssClassForShown);
		}
		hideThis.style.display="none";
	}
	if (showThis && showThis.style.display == 'none') {
		if (cssClassForShown) {
			$(showTab).addClassName(cssClassForShown);
		}
		showThis.style.display="block";
	}
}

function toggleDisplay(elem) {
	elem = $(elem);
	if (elem.style.display == "none") {
		Effect.BlindDown(elem, {duration: 0.3});
	}
	else Effect.BlindUp(elem, {duration: 0.3});
}

function jsonfeed(data) {
	var e = document.getElementById('loginErrorMessage');
	e.innerHTML = data.msg;

	// Set some basic options for the cookie
	var options = { expires: 0, path: '/', domain: '.acs.org' };

	// Preset the value of the cookie
	var value = null;

	// If the session was created, set the cookie value to the session id
	if (data.sessionid) {
		value = data.sessionid;
		// Actually create he cookie
		jQuery.cookie('ERIGHTS', value, options);
		if (document.getElementById('redirectUri')) window.location = document.getElementById('redirectUri').value;
	}
}
function doLogin(smHost) {
	if ($('loginErrorMessage')) {
		$('loginErrorMessage').innerHTML = "Sending Log In information...";
	}
	var username = encodeURIComponent($('acsID').value);
	var password = encodeURIComponent($('password').value);
	var url = smHost + '/portal/signon?username=' + username + '&password=' + password;
	jQuery.ajax({
		  type: "GET",
		  url: url,
		  dataType: "script"
	});
	return false;
}
//Added by Atypon: if there are fewer than 5 items in journalHome, set range.
function setRange(focusList){
	var articles = $(focusList).getElementsByClassName('articleBox');
	var range = $(focusList).down('div.range');
	var size = articles.length;
	if (size < 2){
		range.style.display='none';
		removeViewAllLinks(focusList);
		return;
	}
	if (size < 5){
		range.innerHTML='Now showing 1&ndash;' + size;
		removeViewAllLinks(focusList);
	}
}
//Added by Atypon: if there are fewer than 5 items in journalHome, remove "View All" links
function removeViewAllLinks(focusList){
	$(focusList).down('div.viewAll').style.display='none';
	$(focusList).down('div.viewAllLink').style.display='none';
}

// Alex Kim: function that we'll be using on static pages
function loadAudio(link) {
	var wrapper=$(link).parentNode.parentNode;
	var loadLink=$(wrapper).select('div.button')[0];
	var box=$(wrapper).select('div.audioBox')[0];
	if ($(wrapper).select('div.info')[0]) $(wrapper).select('div.info')[0].style.display="none";
	loadLink.style.display="none";
	box.style.display="block";
}

// a general show/hide toggle function
function toggleView(link,animate) {
	if (!animate) animate=0;
	var target=$(link).up('div').select('[class="toggled"]');
	var linkText=$(link).innerHTML;
	if (target[0].style.display=="none") {
		if (animate=="fade") Effect.Appear(target[0]);
		else target[0].style.display="block";
		$(link).innerHTML=linkText.gsub(/^View /, "Hide ");
	}
	else {
		if (animate=="fade") Effect.Fade(target[0]);
		else target[0].style.display="none";
		$(link).innerHTML=linkText.gsub(/^Hide /, "View ");
	}
}




// Alex Kim: Slideshow Functions for HPs and Site Editor pages
function gotoSlide(target,autoplay) {
	if (!autoplay) autoplay=0; // no autoplay unless designated
	// stop autoplay if this is a non-autoplay request
	if (autoplay=="0") {
		if (window.slideLoop) window.clearInterval(slideLoop);
		$('highlightPlay').show();
		$('highlightPause').hide();
	}
	var nav=$('slideSelect');
	var slides=$('slides');
	var slide=new Array();
	var button=new Array();
	var num=0;
	while (nav.select('li')[num]) {
		button[num]=nav.select('li')[num];
		if(button[num].hasClassName('current')) {
			button[num].removeClassName('current');
		}
		num++;
	}
	var max=num-1; // num ends up being one more than the total # of slides
	for (n=0;n<=max;n++) {
		slide[n]=slides.select('div.slide')[n];
		slide[n].style.display="none";
	}
	// target slide appears; target button gets highlighted
	target=target-1; // slide 1 = slide[0]
	Effect.Appear(slide[target]);
	button[target].addClassName('current');
}
function getCurrent(max) {
	var slideArray=new Array();
	slideArray=$('slideSelect').select('li');
	var max=slideArray.length;
	for (var i=0;i<max;i++) {
		if (slideArray[i].hasClassName('current')) var current=i;
	}
	var current=current+1; // translate array numbering to slide numbering (slide 1=array[0])
	return current;
}
function playSlides(command,initialize) {
	if (!initialize) initialize=0;
	var play=$('highlightPlay');
	var pause=$('highlightPause');

	if (command=="play") {
		// show pause button
		play.hide();
		pause.show();
		// find out how many slides there are
		var max=$('slideSelect').select('li').length;
		// determine which slide is currently displayed
		var n=getCurrent();
		if (n==max) n=1; // last slide loops to first slide
		else n++; // add 1 to go to the next slide
		n=n++; // target the next slide
		if (initialize!=0) n=1; // skip showing initial slide (again) if this is from the autoplay triggered by the loading of the window
		else gotoSlide(n,1); // immediately show next slide if this isn't triggered by autoplay
		// then loop through the slides
		slideLoop=setInterval(
			function() {
				if (n==max) n=1; // last slide loops to first slide
				else n++; // add 1 to go to the next slide
				gotoSlide(n,1);
			}
		,9000) // determines how long each slide displays in autoplay
	}
	else {
		window.clearInterval(slideLoop);
		play.show();
		pause.hide();
	}
}
function changeSlide(slide) {
	var n;
	var slideArray=new Array();
	slideArray=$('slideSelect').select('li');
	var max=slideArray.length;
	var current=getCurrent();
	if (slide=="next") {
		if (current==max) n=1;
		else n=current+1;
	}
	else {
		if (current==1) n=max;
		else n=current-1;
	}
	gotoSlide(n);
}


// new function for Archive first page image
function showFull(target) {
	image=$(target).getElementsByTagName('img')[0];
	text=$(target).getElementsByTagName('span')[0];
	if (image.style.width!="99%") {
		$(image).writeAttribute("style","width:99%; position:static;");
		text.style.width="611px";
		text.innerHTML="Click to increase image size";
	}
	else {
		$(image).writeAttribute("style","width:auto; position:relative;");
		text.style.width="780px";
		text.innerHTML='Click to decrease image size<span class="bigx">X</span>';
	}
}

function toggleBooksTabs(tab) {
	var yearTab=$('ebookYearTab');
	var divisionTab=$('ebookDivTab');
	var yearLayer=$('booksByYear');
	var divisionLayer=$('booksByDivision');

	if (tab=="year" && yearTab.readAttribute('class')=="nowShowing") return false;

	else if (tab=="division" && divisionTab.readAttribute('class')=="nowShowing") return false;

	else if (tab=="year") {
		divisionLayer.hide();
		yearLayer.show();
		divisionTab.writeAttribute("class", "");
		yearTab.writeAttribute("class", "nowShowing" );
	}
	else {
		yearLayer.hide();
		divisionLayer.show();
		yearTab.writeAttribute("class", "");
		divisionTab.writeAttribute("class", "nowShowing" );
	}
	return false; // prevent user from jumping to top of the page
}

/* 4 Quick Search Functions */
function toggleQS(section) {
	//hide all forms
	$('qsSearch').style.display="none";
	$('qsCitation').style.display="none";
	$('qsDOI').style.display="none";

	//set all tabs to default styles
	$('qsTabSearch').removeClassName('active');
	$('qsTabCitation').removeClassName('active');
	$('qsTabDOI').removeClassName('active');

	if (section=="search") {
		$('qsSearch').style.display="block";
		$('qsTabSearch').addClassName('active');
		$('qsSearchString').focus();
	}
	else if (section=="citation") {
		$('qsCitation').style.display="block";
		$('qsTabCitation').addClassName('active');
		$('qsCitVol').focus();
	}
	else if (section=="doi") {
		// detect if someone started putting a DOI into the search field before clicking on the DOI tab, and transfer that value to the DOI field
		var sv=$('qsSearchString').value;
		if (sv.startsWith('10.1021/')) $('qsDOIField').value=sv;

		$('qsDOI').style.display="block";
		$('qsTabDOI').addClassName('active');
		// a dumb way of shifting focus to the text box; had to be done for Safari
		if ($('qsDOIField').value=="10.1021/" || $('qsDOIField').value=="") $('qsDOIField').value="10.1021/";
		$('qsDOIField').focus();
	}
}

/*modified by Atypon*/
function validateSearch() {
	var select = document.getElementById("qsSearchArea");
	var searchArea = select.options[select.selectedIndex].value;
	var searchString = document.getElementById("qsSearchString").value;

	if (searchString == "") {
		alert('Please enter search terms before running your search.');
		return false;
	}

	document.getElementById("simpleSearchArea").name = searchArea;
	document.getElementById("simpleSearchArea").value = searchString;

	document.getElementById("qsSearch").submit();
}
function validateCitation() {
	var title = $('qsCitTitle');
	var volume = $('qsCitVol');
	var page = $('qsCitPage');

	if (title.value == "-") {
		alert('Please select a Journal or Book Series before running your search.');
		return false;
	}
	else if (volume.value == "" || !volume.value.toString().match(/^[-]?\d*\.?\d*$/)) {
		alert('Please enter a valid Volume before running your search.');
		return false;
	}
	else if (page.value == "")
	{
		alert('Please enter a valid Page before running your search.');
		return false;
	}

	parent.window.location="/action/quickLink?quickLinkJournal=" + title.value + "&quickLinkVolume=" + volume.value + "&quickLinkPage=" + page.value;
}
function validateDOI() {
	var doi=$('qsDOIField').value;

	// detect manuscript ids and prepend them with 10.1021/ to turn them into valid DOIs
	if (!doi.startsWith('10.1021/')) {
		doi="10.1021/"+doi;
	}
	else if (doi.length < 10) {
		alert('Please enter a valid ACS Publications DOI before running your search.');
		return false;
	}

	// detect book DOIs
	if (doi.startsWith('10.1021/bk-')||doi.startsWith('10.1021/ba-')) {
		// detect books
		if (doi.length < 21) {
			parent.window.location="/doi/book/" + encodeURIComponent(doi);
		}
		// all others must be chapters
		else parent.window.location="/doi/abs/" + encodeURIComponent(doi);
	}
	else parent.window.location="/doi/abs/" + encodeURIComponent(doi);
}

/* to toggle the ASAP/JAMs only button */
function toggleDateRange(checkbox) {
	var df = $('dateFilter');
	if (checkbox.checked) df.hide();
	else df.show();
}

/* show/hide the Title Results */
function toggleTitleResults(anchor) {
	var results=$('titleResultsLayer');
	if (results.style.display=="none") {
		Effect.BlindDown(results);
		$(anchor).writeAttribute("class","showing");
	}
	else {
		Effect.BlindUp(results);
		$(anchor).writeAttribute("class","");
	}
}

/* submit showBookSeries with correct values in query */
function submitShowBookSeries() {
	var select = document.getElementById("bookYear");
	var index = select.selectedIndex;
	var selectedValue = select.options[index].value;

	var beforeYear = document.getElementById("beforeYear");
	beforeYear.value = selectedValue;

	var form = document.getElementById("bookYearForm");
    getFormInput(form.name, 'startPageYear').value = 0;

	form.submit();

}

/* Browse by issue */
Event.observe(window, 'load', function() {
	if (!window.decadesArray) return;
	var inDecade = $('inDecade');
	var decadesSize = window.decadesArray.length;
	if (decadesSize < 2) { //hide the selDecade if there is only one Decade
		populateVolumeFromIndex(0);
		$('selDecade').style.display = 'none';
		reDrawIssueJump();
		return;
	}
	$('selDecade').style.display = 'block';
	for (var k = 0; k < decadesSize; k++) {
		var option = $(document.createElement("option"));
		option.value = k;
		option.innerHTML = window.decadesArray[k].label;
		inDecade.appendChild(option);
	}
	inDecade.observe('change', populateVolume);
});

function populateVolume(event) {
	var select = event.element();
	var index = select.value;

	// put a "loading" message in place until the volume pulldown is populated
	// also reset the Select Issue pulldown to prevent confusion
	// had to target the divs because Explorer doesn't handle innerHTML for <select> properly
	var volSelect = $('selVolume');
	var issSelect = $('selIssue');

	var issueJumpForm = $('issueJump');
	var inputDecade = issueJumpForm['inDecade'];
	if (index=="") {
		volSelect.innerHTML = '<select id="inVolume"><option>Select Volume</option></select>';
		issSelect.innerHTML = '<select id="inIssue"><option>Select Issue</option></select>';
	}
	else {
		volSelect.innerHTML = '<select id="inVolume"><option>Loading...</option></select>';
		issSelect.innerHTML = '<select id="inIssue"><option>Select Issue</option></select>';
	}

	populateVolumeFromIndex(index);
}

function populateVolumeFromIndex(index) {
	var decade = window.decadesArray[index];
	var journalCode = window.journalCode;
	if (!decade || ! journalCode) return;
	var volumeArray = decade.volumeArray;
	if (!volumeArray) {
		new Ajax.Request('/page/journal/decade.jsp?journalCode='+journalCode+'&key='+decade.key, {
		  method: 'get',
		  onSuccess: function(transport) {
			  if (transport.headerJSON) {
				window.decadesArray[index].volumeArray = transport.headerJSON.volumeArray;
				populateVolumeFromIndex(index);
			  }
		  }
		});
		return;
	}
	var volumeSize = volumeArray.length;
	var inVolume = $('inVolume');
	$('selVolume').style.display = 'block';
	inVolume.innerHTML = "";
	var option = document.createElement("option");
	option.innerHTML = "Select Volume";
	inVolume.appendChild(option);
	for (var k = 0; k < volumeSize; k++) {
		option = $(document.createElement("option"));
		option.value = k;
		option.decade = index;
		option.innerHTML = volumeArray[k][1];
		inVolume.appendChild(option);
	}
	inVolume.observe('change', populateIssue);
}

function populateIssue(event) {
	var select = event.element()
	var volumeIndex = select.value;
	var options = select.options;
	var found = false;
	var decadeIndex = 0;
	for (var k = 0; (k < options.length && !found); k++) {
		found = options[k].selected;
		decadeIndex = options[k].decade;
	}
	populateIssueFromIndex(decadeIndex, volumeIndex);
}
function populateIssueFromIndex(decadeIndex, volumeIndex) {
	var decade = window.decadesArray[decadeIndex];
	var volumeArray = decade.volumeArray[volumeIndex];
	var issues = volumeArray[2];//issue Arrays
	if (issues.length == 0) {
		return;
	}

	if (issues.length == 1 && decade.volumeArray.length == 1 && window.decadesArray.length == 1) {
		//if this issue is the only issue of this journal in the current area
		$('selIssue').style.display = 'none';
		reDrawIssueJump();
		return;
	}
	var inIssue = $('inIssue');

	inIssue.innerHTML = "";
	var option = document.createElement("option");
	option.innerHTML = "Select Issue";
	inIssue.appendChild(option);
	for (var k = 0; k < issues.length; k++) {
		option = $(document.createElement("option"));
		option.value = '/toc/' + journalCode + '/' + volumeArray[0] + '/' + issues[k][0];//the first one is issue#
		var pageRange = issues[k][1];
		if (pageRange && pageRange.length != 0){
			pageRange = "/("+pageRange+")";
		}
		option.innerHTML = 'Iss. '+ issues[k][0] + pageRange;//second value is label
		inIssue.appendChild(option);
	}
}

function respondToClick() {
	var issueJumpForm = $('issueJump');
	var inputIssue = issueJumpForm['inIssue'];
	if ($F(inputIssue) == "" || $F(inputIssue) == "Select Issue") {
		alert('Please select both a Volume and Issue before clicking the "Go" button.');
		return false;
	}
	window.location = $F(inputIssue)
}

function reDrawIssueJump() {
	var e = $('issueJump');
	e.hide();
	e.show();
}

/* Normal/Mobile Toggle Site Function */
function useSite(type) {
	if (type=="mobile") createCookie('useMobile','yes',0);
	else createCookie('useMobile','no',0);
	window.location.reload();
}

