//function to fix the IE rollover 
function fixIE6flicker(fix) {
 try {
  document.execCommand("BackgroundImageCache", false, fix);
 } catch(err) { }
}
fixIE6flicker(true);

//Global variable used to hold old CTA string
var oldSearchCTA = "";
var searchFocused = false;

//Hide the "search..." CTA string
function hideSearchCTA(ctrlName)
{
	if ((ctrlName) && (!searchFocused))
	{
		oldSearchCTA = ctrlName.value;
		ctrlName.value = "";
	}
}

//Show the CTA string "search..." if no search entered
function showSearchCTA(ctrlName)
{
	if ((ctrlName) && (ctrlName.value.length == 0))
	{
		ctrlName.value = oldSearchCTA;
		searchFocused = false;
	}
	else
		searchFocused = true;

}

//suckerfish menu for IE
sfHover = function() {
	if(document.getElementById("pnav")) {
		var sfEls = document.getElementById("pnav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function trackPDF(linkTarget){
	loc = linkTarget;
	dom = document.domain;
	finalLoc = loc.substring(dom.length+7,loc.length);				
	pageTracker._trackPageview(finalLoc);
}

function toggleFontLarge() {
	loc = String(document.location);	
	dom = document.domain;
	finalLoc = loc.substring(dom.length+7,loc.length);

	eventTracker._trackPageview(finalLoc + "?font=Large");
	var content = $('block01');
	content.addClassName('largeText');		
	Set_Cookie('ij-FontSize','large', '', '/', '', '');
}

function toggleFontSmall() {
	loc = String(document.location);	
	dom = document.domain;
	finalLoc = loc.substring(dom.length+7,loc.length);

	eventTracker._trackPageview(finalLoc + "?font=Small");	
	var content = $('block01');
	if (content.hasClassName('largeText')) {
		content.removeClassName('largeText');
	}
	Set_Cookie('ij-FontSize','small', '', '/', '', '');
}

function showModal(url,h) {
	var bodytag = $$("body");
	var modalheight;
	if (h=='large') {
		modalheight = 600;
		}
	else if (h=='' || h=='small') {
		modalheight:400;
		}
	bodytag[0].toggleClassName('modal');
	Dialog.alert({url: url, options: {method: 'get'}}, {className: "alphacube", width:478, height:modalheight});
}
function hideModal() {
	var bodytag = $$("body");
	bodytag[0].toggleClassName('modal');
	Dialog.okCallback();
}

function openPopupWindow(url) {
	window.open (url,"mywindow","width=480,height=600,scrollbars=yes,resizable=yes,status=yes,toolbar=no,location=no,menubar=no");
}

//displays main feature content section and sets tab states
function setMainfeature(el) {
		var amt = $$('#currentissue .item');
		var lnkAmt = $$('#currentissuenav li');
		var footerAmt = $$('#currentissue_footer .footer')
		var section;
		for (var i=0;i<lnkAmt.length;i++) {
			if (el.parentNode == lnkAmt[i]) {
				section = i;
			}
		}
	
		for (var j=0;j<lnkAmt.length;j++) {
			if (j != section) {
				if (amt[j].hasClassName('showBlock')) {
					amt[j].removeClassName('showBlock');
					amt[j].addClassName('hidden');
				}
				if (lnkAmt[j].hasClassName('active')) {
					lnkAmt[j].removeClassName('active');
				}
				if (footerAmt[j].hasClassName('showBlock')) {
					footerAmt[j].removeClassName('showBlock');
					footerAmt[j].addClassName('hidden');
				}
			}
			else {
				amt[j].removeClassName('hidden');
				amt[j].addClassName('showBlock');
				footerAmt[j].removeClassName('hidden');
				footerAmt[j].addClassName('showBlock');
				lnkAmt[j].addClassName('active');
				pageTracker._trackPageview("/index.asp?tab=" + (j+1));
			}
		}
	}
// Open popup window to send article to a colleague
function openSendArticlePopupWindow(url){
	window.open (url,"mywindow","width=460,height=780,scrollbars=yes,resizable=yes,status=yes,toolbar=no,location=no,menubar=no");
}

function Set_Cookie( name, value, expires, path, domain, secure ){
var today = new Date();
today.setTime( today.getTime() );


if (expires){
	expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ ){
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		if ( cookie_name == check_name ){
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 ){
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ){
		return null;
	}
}

// Does pagination hiding and unhiding page sections are included as part of the page already
function page(newPage,cmd) {
	if (newPage==0) {
		switch (cmd)
		{
			case 'first':
				currentPage=1;
				break;
			case 'previous':
				if (currentPage!=1) {
					currentPage=currentPage-1;
				}
				break;
			case 'next':
				if (currentPage!=pages) {
					currentPage=currentPage+1;
				}
				break;
			case 'last':
				currentPage=parseInt(pages);
				break;
		}
	}
	else {
		currentPage = newPage;
	}

	loc = String(document.location);
	dom = document.domain;
	finalLoc = loc.substring(dom.length+7,loc.length);
	
	pageTracker._trackPageview(finalLoc + "?page=" + currentPage);
	
	// Showing / Hiding "Pages"
	var pages_array = $$('div.section_container div.pages');
	var i=0;
	while (i!=pages_array.length)
	{
		//pages_array[i].toggleClassName('hidden');
		if (i+1==currentPage) {
			pages_array[i].removeClassName('hidden');
			pages_array[i].addClassName('showBlock');
		}
		else {
			pages_array[i].removeClassName('showBlock');
			pages_array[i].addClassName('hidden');
		}
		i=i+1;
	}
	
	// Activating / Inactivating Page Index
	var pages_index = $$('div.pagination a');
	i=2;
	while (i!=pages_index.length-2)
	{
		if (i==currentPage+1) {
			if (!pages_index[i].hasClassName('active')) {
				pages_index[i].addClassName('active');
			}
		}
		else {
			if (pages_index[i].hasClassName('active')) {
				pages_index[i].removeClassName('active');
			}
		}
		i=i+1;
	}
	pageCounter();
	extraInfo();
	setPageIndexes();
}

// Displays the page being listed on an index page (i.e. Page 1 of 8)
function pageCounter() {
	document.getElementById('page_count').innerHTML='Page ' + currentPage + ' of ' + pages;
}

// Displays the number of items being listed on an index page (i.e. 1-15 of 110)
function extraInfo () {
	if (currentPage==pages) {
		document.getElementById('extra_info').innerHTML=((currentPage-1)*pageSize)+1 + '-' + matches + ' of ' + matches;
	}
	else {
		document.getElementById('extra_info').innerHTML=((currentPage-1)*pageSize)+1 + '-' + currentPage*pageSize + ' of ' + matches;
	}
}

// Hiding / Unhiding page indexes for Index Pages mostly based on a folder listing
function setPageIndexes() {
	var countEndPg;
	if (currentPage < parseInt(maxPageIndex)) {
		if (parseInt(pages) > parseInt(maxPageIndex)) {
			countEndPg = parseInt(maxPageIndex);
		}
		else {
			countEndPg = parseInt(pages);
		}
	}
	else if ((currentPage+1) < parseInt(pages)) {
		countEndPg = currentPage+2;
	}
	else {
		countEndPg = parseInt(pages);
	}
	
	var pcPageNum;
	if ((countEndPg-parseInt(maxPageIndex)+1) > 1) {
		pcPageNum = countEndPg-parseInt(maxPageIndex)+1;
	}
	else {
		pcPageNum = 1;
	}
	//alert ('start: ' + pcPageNum + ' end: ' + countEndPg);

	// Activating / Inactivating Page Indexes
	var pages_index = $$('div.pagination a');
	var i=2;
	while (i!=pages_index.length-2)
	{
		if ((i-1 > pcPageNum-1) && (i-1 < countEndPg+1)) {
			pages_index[i].removeClassName('hidden');
		}
		else {
			pages_index[i].addClassName('hidden');
		}
		i=i+1;
	}
}