function imgDescription() {
    var valid = document.turbnav.valid.options[document.turbnav.valid.selectedIndex].text;

    var result = "Turbulence product valid at " + valid;
    return result;
}

function changeIt() {
    var fl = document.turbnav.flightlevel.options[document.turbnav.flightlevel.selectedIndex].value;
    var valid = document.turbnav.valid.options[document.turbnav.valid.selectedIndex].value;

    var name = valid + "_gtg_" + fl + ".gif";
    var pos  = 1 + document.content.src.lastIndexOf('/');
    var curr = document.content.src.substring(pos);

    if (name != curr) {
        document.printing.alt_text.value = imgDescription();
        document.printing.image_source.value = "/data/turbulence/" + name;

		document.content.src = document.printing.image_source.value
		document.content.title = document.printing.alt_text.value;
		document.content.alt = document.printing.alt_text.value;
    }
}

function nextFL(dir) {
    var sel = document.turbnav.flightlevel.selectedIndex;
    if (dir < 0) {
        if (sel > 0) {
            document.turbnav.flightlevel.selectedIndex = sel - 1;
            changeIt();
        }
    } else {
        var total = document.turbnav.flightlevel.length - 1;
        if (sel < total) {
            document.turbnav.flightlevel.selectedIndex = sel + 1;
            changeIt();
        }
    }
}

function nextTime(dir) {
    var sel = document.turbnav.valid.selectedIndex;
    if (dir < 0) {
        if (sel > 0) {
            document.turbnav.valid.selectedIndex = sel - 1;
            changeIt();
        }
    } else {
        var total = document.turbnav.valid.length - 1;
        if (sel < total) {
            document.turbnav.valid.selectedIndex = sel + 1;
            changeIt();
        }
    }
}

// It has to be in a function or the prevLoad variable will
// cause infinite recursion
function addChangeIt() {
    var prevLoad = window.onload;
    window.onload = function() {
    if (prevLoad) {
        prevLoad();
        }
        changeIt();
    }
}
addChangeIt();
