// This is used by cliwatch/watch.htm

var now = new Date();
		 
year0 = now.getYear();
//alert("year0="+year0);

if (year0 < 1000)
	year0 = year0 + 1900;
	
month0 = now.getMonth();
date0 = now.getDate();
 
month = month0;
year = year0;
date = date0;

month--;  // display last month and older data
if (date<0)  // only until past 10th of this month
	month--;

if (month<0) {
	month = month + 12;
	year--;
}
		 

//alert("year="+year+" month="+month+" date="+date);

Years = new Array();
Years.length = 0;
for(count = 0; count < year-1999; count++)
	Years[count] = 2000 + count;

Months = new Array("January","February","March","April","May","June","July",
 "August","September","October","November","December");        
 
		 
// browser specific
if (navigator.appName == "Netscape") {
	mnhili = document.monthlyhighlights;
	rcntmaps = document.recentmaps;
} else {
	mnhili = document.all.monthlyhighlights;
	rcntmaps = document.all.recentmaps;
}
		
initializeForm()
//getlink()

function initializeForm() {

	// fill first form
	mnhili.Year.length = 0;
//alert("Years.length="+Years.length);
	for(count = 0; count < Years.length; count++) {
		if (count == year - 2000) {  // set current year as default
			mnhili.Year.options[count] = new Option(Years[count],"",1,1);
			mnhili.Year.options[count].selected = 1;
//alert("default Year="+Years[count]);
		} else {
			mnhili.Year.options[count] = new Option(Years[count],"",0,0);
			mnhili.Year.options[count].selected = 0;
//alert("Year="+Years[count]);
		}
	}
//alert("mnhili.Year.selectedIndex="+mnhili.Year.selectedIndex);
	fillMonths();
	
	// fill second form
	rcntmaps.rcntmn.length = 0;
	for(count = 0; count < 6; count++) {
		mm = month0 - 1 - count;
		yy = year0;
		if ( mm < 0 ) {
			mm = mm + 12;
			yy = yy - 1;
		}
		if (count == 0)
			rcntmaps.rcntmn.options[count] = new Option(Months[mm]+" "+yy,"",1,1)
		else
			rcntmaps.rcntmn.options[count] = new Option(Months[mm]+" "+yy,"")
	}
}

function fillMonths()	{
	mnhili.Month.length=0;
//alert("Months.length="+Months.length);
//alert("mnhili.Year.selectedIndex="+mnhili.Year.selectedIndex);
	for(count = 0; count < Months.length; count++) {
		if ( mnhili.Year.selectedIndex == year - 2000)
			if ( month == count) {  // show recent month as default for current year
				mnhili.Month.options[count] = new Option(Months[count],"",1,1);
				mnhili.Month.options[count].selected = 1;
				break;
			} else
				mnhili.Month.options[count] = new Option(Months[count],"");
		else
			if ( count == 0 ) { // show first month as default for past years
				mnhili.Month.options[count] = new Option(Months[count],"",1,1);
				mnhili.Month.options[count].selected = 1;
			} else
				mnhili.Month.options[count] = new Option(Months[count],"");
	}
}
		
function getlink()
{
	var linkot;
	
	if (mnhili.Year.selectedIndex<10)
		yy = "0" + mnhili.Year.selectedIndex;
	else
		yy = mnhili.Year.selectedIndex;
		
	if (mnhili.Month.selectedIndex+1<10)
		mm = "0" + (mnhili.Month.selectedIndex + 1);
	else
		mm = mnhili.Month.selectedIndex + 1;
			
	linkto = yy+mm+"/climwatch."+yy+mm+".htm";

	return linkto;
}

function getlink2()
{
	var linkto;
	
	count = rcntmaps.rcntmn.selectedIndex;
	
	mm = month0 - 1 - count;
	yy = year0;
	if ( mm < 0 ) {
		mm = mm + 12;
		yy = yy - 1;
	}

	yy = yy - 2000;
	if (yy<10)
		yy = "0" + yy;
		
	if (mm+1<10)
		mm = "0" + (mm + 1);
	else
		mm = mm + 1;
		
	linkto = "months/m"+mm+"_"+yy;
	linkto = linkto + "." + rcntmaps.datatype.options[rcntmaps.datatype.selectedIndex].value + ".gif";
				
	return linkto;
}

function goseasonalmaps() {

	var theURL;

	pickseason=document.seasonalmaps.season.options[document.seasonalmaps.season.selectedIndex].value;

	dat=document.seasonalmaps.datatype.options[document.seasonalmaps.datatype.selectedIndex].value;

	theURL="seasons/"+pickseason+"."+dat+".gif";	

	return theURL;

}

