function doNext() {
	gotoPage( parseInt(document.forms['listForm'].pageNumber.value)+1 );
}

function doPrevious() {
	gotoPage( parseInt(document.forms['listForm'].pageNumber.value)-1 );
}

function gotoPage( pageNum ) {
	document.forms['listForm'].pageNumber.value = pageNum;
	document.forms['listForm'].submit();
}

function sortBy( order ) {
	document.forms['listForm'].listBy.value = order;
	document.forms['listForm'].submit();
}

var xmlhttp;
var expandDiv;
var currentlyShowing;

function doArticles( issue, divId )
{
	if( expandDiv!=null ) return;

	if( divId == currentlyShowing ) {
		showDiv( divId, true );
		currentlyShowing = null;
		return;
	}

	if( document.getElementById('artExp'+divId).innerHTML != null &&
		document.getElementById('artExp'+divId).innerHTML.length > 0 ) {
        showDiv( divId, false );
        window.location="#"+divId;
	}
	else {
		expandDiv = divId;
		var url = "/journals/articleList.do?QueryType=articles&QueryIndex=journal" +
			"&id=" + document.forms['listForm'].listName.value +
			"&title=" + encodeURIComponent(document.forms['listForm'].title.value) +
			"&issue=" + encodeURIComponent(issue);
		loadXMLDoc(url);
	}
}

function showDiv( divName, hideAll )
{
	if( !hideAll ) { currentlyShowing = divName; }

	var allDivs = document.getElementsByTagName('div');
    for( var i=0; i<allDivs.length; i++ ) {
    	if( allDivs[i].id.match( 'artExp' ) ) {
    		if( !hideAll && allDivs[i].id == 'artExp'+divName ) {
		        setDiv( allDivs[i].id, true );
		    }
		    else {
		    	setDiv( allDivs[i].id, false );
		    }
		}
   	}

	var allImgs = document.getElementsByTagName('img');
    for( var i=0; i<allImgs.length; i++ ) {
    	if( allImgs[i].id.match( 'artImg' ) ) {
    		if( !hideAll && allImgs[i].id =='artImg'+divName ) {
		        allImgs[i].src = "/images/collapse.gif";
		    }
		    else {
		        allImgs[i].src = "/images/expand.gif";
		    }
		 }
     }
}

/* visibility = 'hidden' or 'visible' */
function setDiv( divName, visibility)
{
	var newStyle = 'block';
	if( !visibility ) {
		newStyle = 'none';
	}

	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(divName).style.display = newStyle;
	}
	else {
		if (document.layers) { // Netscape 4
			eval( 'document.'+divName+'.display = "'+newStyle+'"' );
		}
		else { // IE 4
			eval( 'document.all.'+divName+'.style.display = "'+newStyle+'"' );
		}
	}
}

function loadXMLDoc(url)
{
    xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e)	{ try {	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch (e)	{ try {	xmlhttp = new XMLHttpRequest(); }
		catch (e)	{ xmlhttp = false; }}
	}
	if (!xmlhttp) {
		alert("Cannot make remote request to server.");
		return;
	}

	xmlhttp.onreadystatechange = processReqChange;
	document.body.style.cursor = "wait";
	xmlhttp.open( "POST", url, true );
	xmlhttp.send( "" );
}

function processReqChange()
{
    // only if req shows "complete"
    if (xmlhttp.readyState == 4) {
    	document.body.style.cursor = "auto";
        // only if "OK"
        if (xmlhttp.status == 200) {
			showDiv( expandDiv, false );
			//alert( "Adding to element "+document.getElementById(expandDiv)+" -  "+expandDiv );
            //document.getElementById('artExp'+expandDiv).innerHTML = "Hello, mum!";
            document.getElementById('artExp'+expandDiv).innerHTML = xmlhttp.responseText;
            window.location="#"+expandDiv;
        } else {
            alert("There was a problem retrieving article listing:\n" + xmlhttp.statusText);
        }
        expandDiv = null;
    }
}


