function changeIt() {
    var file = document.tafnav.valid.options[document.tafnav.valid.selectedIndex].value;
    var when = document.tafnav.valid.options[document.tafnav.valid.selectedIndex].text;
    var curr = document.content.src.replace(/.*\/data/, "/data");
    var where = document.tafnav.region.value;
    var which;
    var condsel = document.getElementById('condsel');

    if (file.match(/tafs/)) {
      which = 'TAF';
      if (document.tafnav.conditions[1].checked) {
        file = file.replace(/PREVAIL/, "TEMPO");
        style = 'of temporary conditions ';
      } else {
        file = file.replace(/TEMPO/, "PREVAIL");
        style = 'of prevailing conditions ';
      }
      if (condsel) {
        condsel.style.display = 'inline';
      }
    } else {
      which = 'METAR';
      style = '';
      if (condsel) {
        condsel.style.display = 'none';
      }
    }

    when = when.replace(/ *[A-z]*$/, "");

    if (file != curr) {
        document.printing.alt_text.value = which + " plot " + style + "for the " + where.toUpperCase() + " region valid at " + when;
        document.printing.image_source.value = file;

		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 nextTime(dir) {
    var sel = document.tafnav.valid.selectedIndex;
    if (dir < 0) {
        if (sel > 0) {
            document.tafnav.valid.selectedIndex = sel - 1;
            changeIt();
        }
    } else {
        var total = document.tafnav.valid.length - 1;
        if (sel < total) {
            document.tafnav.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();
