var thedate = new Date();
var theform;
function setToday() {
	document.calendar.month.options[thedate.getMonth()].selected = true;
	var count = 0;
	var theobj = document.calendar.year;
	theobj.options.length = 0;
	for (var x = thedate.getFullYear(); x >= 2003; x--) {
		theobj.options[count] = new Option(x,x,false,false);
		count++;
		
	}
	validateDays();
	document.calendar.day.options[thedate.getDate()-1].selected = true;
}
function validateDays() {
	var theobj = document.calendar.day;
	theform = document.calendar;

	theobj.options.length = 0;
	var count = 0;
	for (var x = 1; x<=28; x++) {
		if (x<10) {
					theobj.options[count] = new Option(x,"0"+x,false,false);

		} else {
		theobj.options[count] = new Option(x,x,false,false);
		}
		count++;
	}
	for (var x = 29; x<=31; x++) {
		var datecheck = new Date(theform.year.options[theform.year.selectedIndex].value, theform.month.selectedIndex, x);
		if (x == datecheck.getDate()) {
			theobj.options[count] = new Option(x,x,false,false);
		}
		count++;
	}
}
function calendarSubmit() {
	var thesearchdate = new Date(theform.year.options[theform.year.selectedIndex].value, theform.month.selectedIndex, theform.day.options[theform.day.selectedIndex].value);
	if (thesearchdate.getTime() < thedate.getTime()) {
		theform.submit();
	} else {
		window.alert("Sorry, can't search the future.");
	}
}
function sendStory() {
	var address = window.prompt("Enter the email address of the recipient:");
	var headline = document.getElementById("headline").innerText; var content = document.getElementById("content").innerText; var storydate = document.getElementById("date").innerText;
	if (address) {
		window.location = "mailto:" + address + "?subject=" + headline + "&body=From http://www.theAfterNet.net/\n\n" + storydate + "\n\n" + headline + "\n\n" + content;
	}
}
function yesterday2 (which) {
	if (which) {
		thedate = new Date (which);
		thedate = new Date (thedate.getTime()-(3600*24*1000));
	} else {
		thedate = new Date (thedate.getTime()-(3600*24*1000));
	}
	setToday();
	theform.submit();
}
function labelButtons(which) {
	var tempdate = new Date (thedate.getTime()-(3600*24*1000));
	theform.yesterday.value = months[tempdate.getMonth()] + " " + tempdate.getDate() + ", " + tempdate.getFullYear(); 
	if (storydate != undefined) {
		tempdate = new Date (storydate); tempdate = new Date (tempdate.getTime()-(3600*24*1000));
		theform.previous.value = months[tempdate.getMonth()] + " " + tempdate.getDate() + ", " + tempdate.getFullYear(); 
	} else {
		theform.previous.disabled = true;
	}
}
window.onload = function () {
	fixFrames();
	setToday();
	labelButtons(storydate);
};