<!--

var yearStart=1997
var monthStart=12
var dayStart=07

var rootDir="../graphics/";
var satelliteDir="tmi";

var rootLarge = rootDir + satelliteDir + "/graphics_v04/gif/";
var rootSmall = rootDir + satelliteDir + "/graphics_v04/small/";

var cloudFile = rootLarge + get_gif("l");
var rainFile = rootLarge + get_gif("r");
var vaporFile = rootLarge + get_gif("v");
var windFile = rootLarge + get_gif("w");
var sstFile = rootLarge + get_gif("s");
var windzFile = rootLarge + get_gif("z");


var otherDisplay=false

var year,month,day

var firstY,firstM,firstD
var lastY,lastM,lastD

var defaultYearIdx

var yearEnd = yearEnd_nrt
var monthEnd = monthEnd_nrt
var dayEnd = dayEnd_nrt

year=yearEnd; month=monthEnd; day=dayEnd;

firstY = yearStart; firstM = monthStart; firstD = dayStart;
lastY = yearEnd; lastM = monthEnd; lastD = dayEnd;

defaultYearIdx = yearEnd - yearStart + 1;


function year_options() {
	options = "<OPTION VALUE=" + year + ">Year"
	for (var i=yearStart; i<=yearEnd; ++i) {
		options += "<OPTION VALUE=" + i 
		if (year == i) options += " selected>"
		else options += ">"
		options += i
	}
	return options
}


function month_options() {
	options = "<OPTION>Month"
	for (var i=1; i<=12; ++i) {
		options += "<OPTION" 
		if (i ==monthEnd) options += " selected>"
		else options += ">"
		options += month_names[i]
		<!-- options += i	
	}
	return options
}


function day_options() {
	options = "<OPTION>Day"
	for (var i=1; i<=31; ++i) {
		options += "<OPTION" 
		if (i == dayEnd) options += " selected>"
		else options += ">"
		if (i < 10) options += "0"
		options += i
	}
	return options
}


function range(num, beginMonth, beginDay, beginYear, endMonth, endDay, endYear) {
	this.num = num;
	this.beginMonth = beginMonth;
	this.beginDay = beginDay;
	this.beginYear = beginYear;
	this.endMonth = endMonth;
	this.endDay = endDay;
	this.endYear = endYear;
}


function valid_day(inDay) {
	if (month == 2) {
		if (inDay > get_Feb_length()) return false;
	}
	else if (inDay > month_lengths[month]) return false;
	return true;
}


function reset_index() {
	form = document.forms["select_date"];

	form.year.options[defaultYearIdx].selected = true;
	form.month.options[monthEnd].selected = true;
	form.day.options[dayEnd].selected = true;
}


function within_range() {

	if ((year == yearStart) && (month == monthStart) && (day < dayStart)) return false;
	if ((year == yearStart) && (month <  monthStart)) return false;
	if ((year <  yearStart)) return false;

	if ((year == yearEnd) && (month== monthEnd) && (day > dayEnd)) return false
	if ((year == yearEnd) && (month > monthEnd)) return false;
	if ((year >  yearEnd)) return false
	return true;
}

function set_year() {
	form = document.forms["select_date"];
	ySI = form.year.selectedIndex
	if (ySI == 0) { form.year.options[defaultYearIdx-(yearEnd-year)].selected = true; }
	else year = parseInt(form.year.options[ySI].value);
}

function set_month() {
	form = document.forms["select_date"];
	mSI = form.month.selectedIndex;
	if (mSI == 0) { form.month.options[month].selected = true; }
	else month = mSI
}

function set_day() {
	form = document.forms["select_date"];
	dSI = form.day.selectedIndex;
	if (dSI == 0) { form.day.options[day].selected = true; }
	else day = dSI
}


function valid_select() {
	if ( !exist_data()) {
		rangeMsg = "TMI 3-day data is available\n";
		rangeMsg += " from " + monthStart + "/"
		rangeMsg += dayStart + "/" + yearStart + " to " + monthEnd + "/" + dayEnd + "/" + yearEnd +".\n"
		rangeMsg += "Please check your selection.";
		alert(rangeMsg);
		return false
	}
	return true
}


function convert(inStr) {
	if (inStr < 10) return ("0" + inStr);
	return inStr;
}


function get_gif(par) {
	gifName = "y" + year + "/m" + convert(month) + "/" + par + year;
	if (month == 10) gifName += "a";
	else if (month == 11) gifName += "b";
	else if (month == 12) gifName += "c";
	else gifName += month;
	gifName += convert(day);
	gifName += ".gif";
	return gifName;
}

function display_image() {
	form = document.forms["select_date"];

	if (otherDisplay || valid_select()) {
		outputText = year + "/" + convert(month) + "/" + convert(day) + " - 3 day average";

		cloudFile = rootLarge + get_gif("l");
		rainFile = rootLarge + get_gif("r");
		vaporFile = rootLarge + get_gif("v");
		windFile = rootLarge + get_gif("w");
		windzFile = rootLarge + get_gif("z");
		sstFile = rootLarge + get_gif("s");

		form.output.value = outputText;

		document.images["cloud"].src = rootSmall + get_gif("l");	
		document.images["rain"].src = rootSmall + get_gif("r");	
		document.images["vapor"].src = rootSmall + get_gif("v");	
		document.images["wind"].src = rootSmall + get_gif("w");
		document.images["windz"].src = rootSmall + get_gif("z");
		document.images["sst"].src = rootSmall + get_gif("s");

		otherDisplay = false 
	}
}


function display_next() {
	otherDisplay = true
	form = document.forms["select_date"]
	day++

	if (!valid_day(day)) {day = 1; month++}
	if (month == 13) {year++; month = 1}

	if (!exist_data()) {
		if ((year > lastY) || (year == lastY && month > lastM) || (year == lastY && month==lastM && day > lastD)) {
			msg ="Sorry. Data are not available"
			msg +=" after "+ lastM + "/" + lastD + "/" + lastY + ".\n"
			msg += "Images for " + lastM + "/" +lastD +"/" +lastY + " will be displayed"
			alert(msg)
			display_last()
		}
		else if ((year < firstY) || (year == firstY && month < firstM)) display_first()
	}

	else {
		form.year.options[year-yearStart+1].selected = true
		form.month.options[month].selected = true
		form.day.options[day].selected = true
		display_image()
	}
}


function display_prev() {
	otherDisplay = true
	form = document.forms["select_date"];
	day--

	if(day == 0) {
		month--
		if (month == 0) {year--; month = 12}
		if (month == 2) {day = get_Feb_length()}
		else {day = month_lengths[month]}
	}

	if (!exist_data()) {
		if ((year < firstY) || (year == firstY && month < firstM) || (year == firstY && month == firstM && day <firstD)) {
			msg ="Sorry. Data are not available"
			msg +=" before "+ firstM + "/" + firstD + "/" + firstY + ".\n"
			msg += "Images for " + firstM + "/" +firstD +"/" +firstY + " will be displayed"
			alert(msg)
			display_first()
		}
		else if ((year > lastY) || (year == lastY && month > lastM)) display_last()
	}

	else {
		form.year.options[year-yearStart+1].selected = true
		form.month.options[month].selected = true
		form.day.options[day].selected = true
		display_image()
	}
}


function display_first() {
	year = firstY
	form.year.options[year-yearStart+1].selected = true
	month = firstM
	form.month.options[month].selected = true
	day = firstD
	form.day.options[day].selected = true
	display_image()
}


function display_last() {
	year = lastY
	form.year.options[year-yearStart+1].selected = true
	month = lastM
	form.month.options[month].selected = true
	day = lastD
	form.day.options[day].selected = true
	display_image()
}


function get_help() {
	spawn_window("tmi_daily_help.html","help");
}


function data_may_need_refreshing() {
	return(0);
}


// -->