// JavaScript Document
//Global variables to support continuous calendar
//Author: Steven Grindle
//Last revision: 2009 May 30
var monthName = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
var month3names="JanFebMarAprMayJunJulAugSepOctNovDec";
var day_name = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
/*
var date_start = new Date(2009,4-1,19,12,0,0,0); //Sunday  Apr 19, 2009 of the first week in T.E.S.T 2009 calendar
var date_stop = new Date(2009,8-1,9,12,0,0,0); //Sunday Aug 9, 2009 of the last week in T.E.S.T 2009 calendar
*/
var system_timedate = new Date();
//Use local computer time to set the first week of the calendar that is displayed
if((system_timedate<date_start)||(variable_timedate>date_stop)){
	system_timedate = date_start;
	//In case the user's system clock is wrong.
	//Include option for the user to set the first week of the calendar??
}
//document.write("1. system_timedate = " + system_timedate+ "<br />");
//error checking sg
var variable_timedate = new Date(system_timedate.getFullYear(),system_timedate.getMonth(),system_timedate.getDate()); 
//system_timedate is fixed until next refresh and variable timedate is rendered in the continuous calendar.
variable_timedate.setHours(12,0,0,0);
//set time of variable_timedate to exactly noon in case of a timeshift due to daylight savings adjustments
system_timedate = variable_timedate;
system_today = system_timedate.getTime();
//system_today is an integer used to flag today in the calendar
//document.write("variable_timedate = " + variable_timedate.getTime()+ "<br />");
//error checking sg
//document.write("system_timedate = " + system_timedate.getTime()+ "<br />");
//error checking sg
//var text_date = variable_timedate.toDateString();
//diagnostic
//document.write("3. text_date = system_timedate.toDateString(); " + text_date+ "<br />");
//error checking sg
//document.write("4. date_start = new Date(2008, 7, 24); " + date_start+ "<br />");
//error checking sg	
//document.write("5. date_stop = new Date(2009, 4, 17); " + date_stop+ "<br />");
//error checking sg	
var days_before_now = variable_timedate.getDay()+ 7;
//0 becomes 7, 1 becomes 8, 2 becomes 9 so the calendar always starts at Sunday of the previous week regardless of the day of the week of system_timedate
variable_timedate.setTime(variable_timedate.getTime() - days_before_now*86400000);
//1 day x 24 hours/day x 60 minutes/hour x 60 seconds/minute x 1000 milliseconds/second = 86,400,000 milliseconds/day
variable_timedate.setHours(12,0,0,0);
//set time of variable_timedate to exactly noon in case of a timeshift due to daylight savings adjustments
var sunday_previous_week = new Date(variable_timedate.getFullYear(),variable_timedate.getMonth(),variable_timedate.getDate(),12,0,0,0);
//Integer sunday_previous_week is an integer represented the Sunday of the week previous to the local computer's date

function alert_date(integer_timedate_value,flag1){
	//diagnostic that takes an integer timedate value and displays (written or alert)
	if(flag1==1){
		document.write(integer_timedate_value.getFullYear());
		document.write("&nbsp;");
		document.write(monthName[integer_timedate_value.getMonth()]);
		document.write("&nbsp;");
		document.write(integer_timedate_value.getDate());
	}else if(flag1==2){
		alert(integer_timedate_value.getFullYear()+" "+monthName[integer_timedate_value.getMonth()]+" "+integer_timedate_value.getDate());
	}else{
		alert("set flag1 to either 1(write) or 2(alert)");
	}
	flag1=0;
}
