function doSearchIndexTerm(event) {
	var href = getElementById("bobIndex-navigator").href;
    if( trim(document.getElementById("searchTerm").value) =="") {
		alert('please enter index term');
	} else {
		var searchTerm = document.getElementById('searchTerm').value;
		searchTerm = escape(searchTerm)
		var bobIndexURL = href.replace('indexTerm=','indexTerm=' + searchTerm);
         document.location.href = bobIndexURL;
    }
    cancelEvent(event);
    return false;
}

function doSelectIndex(event) {
	var bobIndexSelector = getElementById("bobIndexSelector");
	var bobIndexId = bobIndexSelector[bobIndexSelector.selectedIndex].value;
	var navigationElement = getElementById("bobIndex-navigator");
	var bobIndexUrl = navigationElement.href;
	if (bobIndexId.length > 0) {
	    bobIndexUrl = replaceParamValueInURL(bobIndexUrl, 'bobIndexId', bobIndexId)
					  + "&selectedIndex=" + bobIndexSelector[bobIndexSelector.selectedIndex].innerHTML;
	}
	window.location.href= bobIndexUrl;
	cancelEvent(event);
    return false;
}

function doPubYearSelectIndex(event) {
	var pubYearIndexSelector = getElementById("pubYearIndexSelector");
	var pubYearIndexId = pubYearIndexSelector[pubYearIndexSelector.selectedIndex].value;
	var baseURL = "aboutJournal.do?inPS=true";
    var dsForm = document.forms["pubIssuesForm"];
    baseURL += "&userGroupName="+dsForm.userGroupName.value;
    baseURL += "&prodId="+dsForm.prodId.value;
    baseURL += "&actionString=DO_RETRIEVE_PUB_ISSUES";
    baseURL += "&pubYear="+pubYearIndexId;
    baseURL += "&searchType="+dsForm.searchType.value;
    baseURL += "&mcode="+dsForm.mcode.value;
  
    xmlhttp = getXmlHttpRequest();
    xmlhttp.onreadystatechange=pubYearStateChanged;
    xmlhttp.open("GET", baseURL, true);
    xmlhttp.send(null);
	
	cancelEvent(event);
    return false;
}

function pubYearStateChanged() {
    if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
    {
        {
	        document.getElementById("issuesByPubYear").innerHTML = xmlhttp.responseText;
	    }
    } else if (xmlhttp.readyState==1) {
    		
		document.getElementById("issuesByPubYear").innerHTML = "Loading...";
    }
    
}

function doPageInitialization()	 {
	var marklistDivs = document.getElementsBySelector("div.markItem");
	var pgCnt = 0;
	for(var i=0;i<marklistDivs.length;i++){
		var element = marklistDivs[i].getElementsByTagName("INPUT")[0];
         if (element.checked ==true) {
         	pgCnt += 1;
         }
    }
	PG_CNT = pgCnt;
}

////////////////////////////////////////////////////////////////////////////////
//
// This function will give any text input that invokes it via onKeyPress the
// ability to call doSearchIndexTerm().
//
// If NN4, the character code is contained in NN4's which property.  Otherwise
// if IE, the character code is contained in IE's keyCode property.
//
// If the character code equals ascii 13 (enter key), then call
// doSearchIndexTerm().
//
////////////////////////////////////////////////////////////////////////////////
function checkEnter( e ) {
    var characterCode;
	if( e && e.which ) {
		e = e;
		characterCode = e.which;
	} else {
		e = event;
		characterCode = e.keyCode;
	}

	if( characterCode == 13 ) {
        doSearchIndexTerm("keypress");
        return false;
    } else {
		return true;
	}
}

////////////////////////////////////////////////////////////////////////////////
//
// This function attaches checkEnter() method via onkeypress to the
// 'searchTerm' text field.
//
////////////////////////////////////////////////////////////////////////////////
function attachTextCheckEnterEvents() {
	if(getElementById("searchTerm")!= null){
	    var searchTerm = getElementById("searchTerm");
		searchTerm.setAttribute("autocomplete","off");
		searchTerm.onkeypress = checkEnter;
	}
}

/***************************************** eBook Event Binding ******************************************/

function attachEbookEvents(){
	attachPopup("docTools-print", openPrintWindow);
	attachPopup("docTools-email", openGaleChildWindow);
	attachPopup("docTools-download", openGaleChildWindow);
	attachPopup("docTools-citation", openGaleChildWindow);
    attachPopup("globalTools-infomark", openInfomarkWindow);
	addClickEventForId("iteratorBar-markDocument", markPageCheckBox);	
	addClickEventForId("bobIndex-navigator", doSearchIndexTerm);
	addChangeEventForId("bobIndexSelector", doSelectIndex);
	if (navigator.appName=="Microsoft Internet Explorer"){
		if(getElementById("pubYearIndexSelector") != null){
		   doPubYearSelectIndex(getElementById("pubYearIndexSelector"));
		}
	}
	addChangeEventForId("pubYearIndexSelector", doPubYearSelectIndex);
    attachTextCheckEnterEvents();
    doPageInitialization();
}

addWindowLoadEvent(attachEbookEvents);