/*
Title: memoissues.js

Summary: This JavaScript file will be used by the All Issues
	pages for Memoirs. It's purpose 
	is to dynamically generate a menu system from an array
	of data passed in my JRNL_TOOLBAR_NAV.pm called issueArray.
Constants:	TABLE_FORMAT - boolean - format for table structure
Globals:	issueArray - read from template, the data for the menu
		html_root - read from template, the root directory
		path - read from template, the distribution
		toc_name - read from template, the html page name
		year - the issue year
		volume - the issue volume number
		issue - the issue number
		rowStart - html to add to start of each row
		rowEnd - html to add to end of each row
*/

var TABLE_FORMAT = 1;

var year = "";
var volume = "";
var issue = "";

var rowStart = "<br />";
var rowEnd = "";

if (TABLE_FORMAT) {
    rowStart = "<tr><td>";
    rowEnd = "</td></tr>";
}

// Create the dropdown list of years. To be run by onLoad.
function loadYears() {
    count = 0;

    for (thisYear in issueArray) {
        document.getElementById('year').options[count] = new Option(thisYear,thisYear);
        count++;		
    }

    // If we only have one year, auto generate the list of volumes.

    if (count == 1) {
        makeMenu(thisYear);
    }

}

// Read in a year or volume and generate the menus.
function makeMenu(year) {
    // Clear the current volume and issue menus.

    count = 0;
    volumeMenu = '';

    for (thisVolume in issueArray[year]) {                
        volumeName = thisVolume;

        if (volumeName < 10 && volumeName.length > 1) {
            volumeName = volumeName.substring(1);
        }

        volumeLink = "<a href=\"/jourcgi/jrnl_toolbar_nav/memo_" + thisVolume + "\">" + volumeName + "</a>";
        volumeMenu += rowStart + volumeLink + rowEnd;
        count++;	
    }

    // If we only have one volume, auto generate the list of issues.
    if (count == 1) {
        // volumeMenu = rowStart+volumeName+rowEnd;
        // makeMenu('volume',thisVolume);
    }

    document.getElementById('volume').innerHTML = volumeMenu;
}

if (window.addEventListener) {
    window.addEventListener('load', loadYears, false);
} else if (window.attachEvent) {
    window.attachEvent('onload', loadYears);
} else {
    window.onload=loadYears;
}


