
var ADAY = 24 * 60 * 60 * 1000; 
var AWEEK = 7 * 24 * 60 * 60 * 1000;

var today = new Date();
var expired = new Date(today);
expired.setTime(expired.getTime()-ADAY);
var expiration = new Date(today);
expiration.setTime(expiration.getTime()+AWEEK*3);

var studentname = "";
var instructorname = "";
var classname = "";
var online = "";
var startString = "";
var starttime = "";
var endString = "";
var endtime = "";



var dayArray = new Array("SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY");
var dateArray = new Array("", "", "", "", "", "", "");
var dueArray = new Array("", "", "", "", "", "", "");

var daysBenchmarks = "</tr><tr><td>&nbsp;</td><td colspan='2' class='benchmarks'>0 to &lt; 2.75 lab hours</td>";
daysBenchmarks += "<td colspan='2' class='benchmarks'>0 present, 2 Absences</td><td>&nbsp;</td><td colspan='3'>";
daysBenchmarks += "Hours checked &amp; verified by Instructor</td><td class='colspacer'>&nbsp;</td><td>&nbsp;</td>";
daysBenchmarks += "</tr><tr><td>&nbsp;</td><td colspan='2' class='benchmarks'>2.75 to &lt; 5.5 lab hours</td>";
daysBenchmarks += "<td colspan='2' class='benchmarks'>.5 present, 1.5 Absences</td><td>&nbsp;</td><td colspan='3'>(initial)</td>";
daysBenchmarks += "<td class='colspacer'>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td colspan='2' class='benchmarks'>";
daysBenchmarks += "5.5 to &lt; 8.25 lab hours</td><td colspan='2' class='benchmarks'>1 present, 1 Absences</td><td colspan='6'>&nbsp;</td>";
daysBenchmarks += "</tr><tr><td>&nbsp;</td><td colspan='2' class='benchmarks'>8.25 to &lt; 11 lab hours</td><td colspan='2' ";
daysBenchmarks += "class='benchmarks'>1.5 present, .5 Absences</td><td colspan='6'>&nbsp;</td></tr><tr><td>&nbsp;</td>";
daysBenchmarks += "<td colspan='2' class='label benchmarks'>11 lab hours</td><td colspan='2' class='benchmarks'>2 present, ";
daysBenchmarks += "0 Absences</td><td colspan='6'>&nbsp;</td></tr></table></body></html>";

var nightsBenchmarks = "</tr><tr><td>&nbsp;</td><td colspan='2' class='benchmarks'>Under 2 lab hours</td>";
nightsBenchmarks += "<td colspan='2' class='benchmarks'>0 present, 2 Absences</td><td>&nbsp;</td><td colspan='3'>";
nightsBenchmarks += "Hours checked &amp; verified by Instructor</td><td class='colspacer'>&nbsp;</td><td>&nbsp;</td>";
nightsBenchmarks += "</tr><tr><td>&nbsp;</td><td colspan='2' class='benchmarks'>2 to &lt; 4 lab hours</td>";
nightsBenchmarks += "<td colspan='2' class='benchmarks'>.5 present, 1.5 Absences</td><td>&nbsp;</td><td colspan='3'>(initial)</td>";
nightsBenchmarks += "<td class='colspacer'>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td colspan='2' class='benchmarks'>";
nightsBenchmarks += "4 to &lt; 6 lab hours</td><td colspan='2' class='benchmarks'>1 present, 1 Absences</td><td colspan='6'>&nbsp;</td>";
nightsBenchmarks += "</tr><tr><td>&nbsp;</td><td colspan='2' class='benchmarks'>6 to &lt; 8 lab hours</td><td colspan='2' ";
nightsBenchmarks += "class='benchmarks'>1.5 present, .5 Absences</td><td colspan='6'>&nbsp;</td></tr><tr><td>&nbsp;</td>";
nightsBenchmarks += "<td colspan='2' class='label benchmarks'>8 lab hours</td><td colspan='2' class='benchmarks'>2 present, ";
nightsBenchmarks += "0 Absences</td><td colspan='6'>&nbsp;</td></tr></table></body></html>";

var genEdBenchmarks = "</tr><tr><td>&nbsp;</td><td colspan='2' class='benchmarks'>Under 1.25 lab hours</td>";
genEdBenchmarks += "<td colspan='2' class='benchmarks'>1 Absence</td><td>&nbsp;</td><td colspan='3'>";
genEdBenchmarks += "Hours checked &amp; verified by Instructor</td><td class='colspacer'>&nbsp;</td><td>&nbsp;</td>";
genEdBenchmarks += "</tr><tr><td>&nbsp;</td><td colspan='2' class='benchmarks'>1.25 to &lt; 2.5 lab hours</td>";
genEdBenchmarks += "<td colspan='2' class='benchmarks'>.5 Present</td><td>&nbsp;</td><td colspan='3'>(initial)</td>";
genEdBenchmarks += "<td class='colspacer'>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td colspan='2' class='benchmarks'>";
genEdBenchmarks += "2.5 lab hours</td><td colspan='2' class='benchmarks'>1 Present</td><td colspan='6'>&nbsp;</td>";
genEdBenchmarks += "</tr></table></body></html>";

var onlineDayBenchmarks = "</tr><tr><td>&nbsp;</td><td colspan='2' class='benchmarks'>0 to &lt; 3 lab hours</td>";
onlineDayBenchmarks += "<td colspan='2' class='benchmarks'>0 present, 1 Absences</td><td>&nbsp;</td><td colspan='3'>";
onlineDayBenchmarks += "Hours checked &amp; verified by Instructor</td><td class='colspacer'>&nbsp;</td><td>&nbsp;</td>";
onlineDayBenchmarks += "</tr><tr><td>&nbsp;</td>";
onlineDayBenchmarks += "<td colspan='2' class='label benchmarks'>3 lab hours</td><td colspan='2' class='benchmarks'>1 present, ";
onlineDayBenchmarks += "0 Absences</td><td colspan='6'>&nbsp;</td></tr></table></body></html>";

var onlineNightBenchmarks = "</tr><tr><td>&nbsp;</td><td colspan='2' class='benchmarks'>0 to &lt; 2 lab hours</td>";
onlineNightBenchmarks += "<td colspan='2' class='benchmarks'>0 present, 1 Absences</td><td>&nbsp;</td><td colspan='3'>";
onlineNightBenchmarks += "Hours checked &amp; verified by Instructor</td><td class='colspacer'>&nbsp;</td><td>&nbsp;</td>";
onlineNightBenchmarks += "</tr><tr><td>&nbsp;</td>";
onlineNightBenchmarks += "<td colspan='2' class='label benchmarks'>2 lab hours</td><td colspan='2' class='benchmarks'>1 present, ";
onlineNightBenchmarks += "0 Absences</td><td colspan='6'>&nbsp;</td></tr></table></body></html>";

function setDue(dueday){
	for(i=0;i<dueArray.length;i++){ 
		dueArray[i] = dueday==i ? "&larr; DUE" : "&nbsp;";
	}
}

function openSheet(){
if( classname == "General Education" ) benchmarks = genEdBenchmarks;
else if( onlinego == "onlineNot" &&  (endtime == "8:00am" || endtime == "1:00pm")) benchmarks = daysBenchmarks;
else if( onlinego == "onlineNot" &&  (endtime == "5:00pm" || endtime == "5:30pm" || endtime == "6:00pm")) benchmarks = nightsBenchmarks;
else if( onlinego == "onlineDay" && (endtime == "8:00am" || endtime == "1:00pm")) benchmarks = onlineDayBenchmarks;
else if( onlinego == "onlineNight" && (endtime == "5:00pm" || endtime == "5:30pm" || endtime == "6:00pm")) benchmarks = onlineNightBenchmarks;
else {
	alert("You have not filled out the form correctly.  Please make sure your online class time and day match.");
	return;
}
	
var sheethtml = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' ";
sheethtml += "'http://www.w3.org/TR/html4/loose.dtd'>";
sheethtml += "<html><head><title>ICS Lab Attendance Sheet</title>";
sheethtml += "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>";
sheethtml += "<link href='labsheets.css' rel='stylesheet' type='text/css'></head>";
sheethtml += "<body><table><tr><td colspan='6' id='labtitle'>LAB ATTENDANCE SHEET</td>";
sheethtml += "<td colspan='3'>&nbsp;</td><td class='colspacer'>&nbsp;</td><td>&nbsp;</td>";
sheethtml += "</tr><tr><td colspan='6' id='classname' class='emheader'>";
sheethtml += classname + "</td><td colspan='3' id='student' class='headerunderline'>";
sheethtml += studentname + "</td><td class='colspacer'>&nbsp;</td><td>&nbsp;</td></tr>";
sheethtml += "<tr><td colspan='6' class='rowspacer'>&nbsp;</td>";
sheethtml += "<td colspan='3' class='inputlabel rowspacer'><p>Name</p></td>";
sheethtml += "<td class='colspacer'>&nbsp;</td><td>&nbsp;</td></tr>";
sheethtml += "<tr><td colspan='2' id='instructor' class='headerunderline'>";
sheethtml += instructorname + "</td><td width='20'>&nbsp;</td>";
sheethtml += "<td class='headerunderline datetime'>" + startString + "</td>";
sheethtml += "<td class='headerunderline datetime'>" + starttime + "</td>";
sheethtml += "<td>&nbsp;</td><td class='headerunderline datetime'>";
sheethtml += endString + "</td><td class='headerunderline datetime'>" + endtime + "</td>";
sheethtml += "<td>&nbsp;</td><td class='colspacer'>&nbsp;</td><td>&nbsp;</td></tr>";
sheethtml += "<tr><td colspan='3' class='inputlabel rowspacer'>Instructor&rsquo;s Name</td>";
sheethtml += "<td colspan='3' class='inputlabel rowspacer'>Lab Week Start</td>";
sheethtml += "<td colspan='3' class='inputlabel rowspacer'>Lab Week End</td>";
sheethtml += "<td class='rowspacer colspacer'>&nbsp;</td><td class='rowspacer'>&nbsp;</td></tr>";
sheethtml += "<tr><td colspan='8'>&nbsp;</td><td colspan='3' class='emheader'>Time Spent</td></tr>";

for(var tableindex = 1; tableindex <= 6; tableindex++){

	sheethtml += "<tr><td colspan='3'>&nbsp;</td><td class='inputlabel ctr'>In</td>";
	sheethtml += "<td class='inputlabel ctr'>Initials</td><td class='inputlabel ctr'>Out</td>";
	sheethtml += "<td class='inputlabel ctr'>Initials</td><td>&nbsp;</td>";
	sheethtml += "<td class='ctr'>Hours</td><td class='colspacer'>&nbsp;</td><td class='ctr'>Minutes</td></tr>";
	sheethtml += "<tr><td colspan='3' class='label'>" + dayArray[tableindex] + "</td><td class='cell'>&nbsp;</td>";
	sheethtml += "<td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td>";
	sheethtml += "<td>&nbsp;</td><td class='headerunderline'>&nbsp;</td><td class='colspacer'>&nbsp;</td>";
	sheethtml += "<td class='headerunderline'>&nbsp;</td></tr><tr><td class='headerunderline'>";

	if( endtime == "8:00am" && dueArray[tableindex] == "&larr; DUE" ) {
		sheethtml += startString + "</td><td class='inputlabel duecell'>&nbsp;</td><td>&nbsp;</td><td class='cell'>&nbsp;</td>";
		sheethtml += "<td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td>";
		sheethtml += "<td>&nbsp;</td><td class='headerunderline'>&nbsp;</td><td class='colspacer'>&nbsp;</td>";
		sheethtml += "<td class='headerunderline'>&nbsp;</td></tr><tr><td class='inputlabel'>Date</td><td colspan='2'>&nbsp;</td>";
		sheethtml += "<td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td>";
		sheethtml += "<td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td><td>&nbsp;</td>";
		sheethtml += "<td class='headerunderline'>&nbsp;</td><td class='colspacer'>&nbsp;</td>";
		sheethtml += "<td class='headerunderline'>&nbsp;</td></tr>";
		sheethtml += "<tr><td class='bottomborderrow'>" + dateArray[tableindex] + "</td><td class='inputlabel duecell bottomborderrow'>" + dueArray[tableindex] + "</td><td class='bottomborderrow'>&nbsp;</td>";
	}
	
	else if( endtime =="1:00pm"  && dueArray[tableindex] == "&larr; DUE" ) {
		sheethtml += startString + "</td><td class='inputlabel duecell'>&nbsp;</td><td>&nbsp;</td><td class='cell'>&nbsp;</td>";	
		sheethtml += "<td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td>";
		sheethtml += "<td>&nbsp;</td><td class='headerunderline'>&nbsp;</td><td class='colspacer'>&nbsp;</td>";
		sheethtml += "<td class='headerunderline'>&nbsp;</td></tr>";	
		sheethtml += "<tr><td class='headerunderline'>" + dateArray[tableindex] + "</td><td class='inputlabel duecell'>" + dueArray[tableindex] + "</td><td>&nbsp;</td>";
		sheethtml += "<td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td>";
		sheethtml += "<td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td><td>&nbsp;</td>";
		sheethtml += "<td class='headerunderline'>&nbsp;</td><td class='colspacer'>&nbsp;</td>";
		sheethtml += "<td class='headerunderline'>&nbsp;</td></tr>";
		sheethtml += "<tr><td class='inputlabel bottomborderrow'>Dates</td><td colspan='2'class='bottomborderrow'>&nbsp;</td>";
	}
	
	else if( endtime=="5:00pm"  && dueArray[tableindex] == "&larr; DUE"){
		sheethtml += dateArray[tableindex] + "</td><td class='inputlabel duecell'>" + dueArray[tableindex] + "</td><td>&nbsp;</td><td class='cell'>&nbsp;</td>";
		sheethtml += "<td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td>";
		sheethtml += "<td>&nbsp;</td><td class='headerunderline'>&nbsp;</td><td class='colspacer'>&nbsp;</td>";
		sheethtml += "<td class='headerunderline'>&nbsp;</td></tr><tr><td class='inputlabel'>Date</td><td colspan='2'>&nbsp;</td>";
		sheethtml += "<td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td>";
		sheethtml += "<td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td><td>&nbsp;</td>";
		sheethtml += "<td class='headerunderline'>&nbsp;</td><td class='colspacer'>&nbsp;</td>";
		sheethtml += "<td class='headerunderline'>&nbsp;</td></tr>";
		sheethtml += "<tr><td colspan='3' class='bottomborderrow'>&nbsp;</td>";
	}
	
	
	else if( endtime=="5:30pm"  && dueArray[tableindex] == "&larr; DUE"){
		sheethtml += dateArray[tableindex] + "</td><td class='inputlabel duecell'>" + dueArray[tableindex] + "</td><td>&nbsp;</td><td class='cell'>&nbsp;</td>";
		sheethtml += "<td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td>";
		sheethtml += "<td>&nbsp;</td><td class='headerunderline'>&nbsp;</td><td class='colspacer'>&nbsp;</td>";
		sheethtml += "<td class='headerunderline'>&nbsp;</td></tr><tr><td class='inputlabel'>Date</td><td colspan='2'>&nbsp;</td>";
		sheethtml += "<td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td>";
		sheethtml += "<td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td><td>&nbsp;</td>";
		sheethtml += "<td class='headerunderline'>&nbsp;</td><td class='colspacer'>&nbsp;</td>";
		sheethtml += "<td class='headerunderline'>&nbsp;</td></tr>";
		sheethtml += "<tr><td colspan='3' class='bottomborderrow'>&nbsp;</td>";
	}
	
	else {
		sheethtml += dateArray[tableindex] + "</td><td class='inputlabel duecell'>" + dueArray[tableindex] + "</td><td>&nbsp;</td><td class='cell'>&nbsp;</td>";
		sheethtml += "<td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td>";
		sheethtml += "<td>&nbsp;</td><td class='headerunderline'>&nbsp;</td><td class='colspacer'>&nbsp;</td>";
		sheethtml += "<td class='headerunderline'>&nbsp;</td></tr><tr><td class='inputlabel'>Date</td><td colspan='2'>&nbsp;</td>";
		sheethtml += "<td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td>";
		sheethtml += "<td class='cell'>&nbsp;</td><td class='cell'>&nbsp;</td><td>&nbsp;</td>";
		sheethtml += "<td class='headerunderline'>&nbsp;</td><td class='colspacer'>&nbsp;</td>";
		sheethtml += "<td class='headerunderline'>&nbsp;</td></tr>";
		sheethtml += "<tr><td colspan='3' class='bottomborderrow'>&nbsp;</td>";
	}


	sheethtml += "</td><td class='cell bottomborderrow'>&nbsp;</td><td class='cell bottomborderrow'>&nbsp;</td>";
	sheethtml += "<td class='cell bottomborderrow'>&nbsp;</td><td class='cell bottomborderrow'>&nbsp;</td><td>&nbsp;</td>";
	sheethtml += "<td class='headerunderline'>&nbsp;</td><td class='colspacer'>&nbsp;</td><td class='headerunderline'>&nbsp;</td>";
	sheethtml += "</tr><tr><td colspan='7' class='topborderrow'>&nbsp;</td><td colspan='4'>&nbsp;</td></tr>";
	
}

sheethtml += "<td colspan='4' class='rowspacer'>&nbsp;</td></tr><tr><td colspan='6'>&nbsp;</td><td colspan='2' class='rowspacer label right'>";
sheethtml += "Total&nbsp;Lab&nbsp;Time&nbsp;This&nbsp;Week:</td><td class='rowspacer headerunderline boldunderline'>&nbsp;</td>";
sheethtml += "<td class='rowspacer colspacer'>&nbsp;</td><td class='rowspacer headerunderline boldunderline'>&nbsp;</td>";
sheethtml += "</tr><tr><td colspan='3' class='headerunderline'>&nbsp;</td><td>&nbsp;</td><td colspan='3' class='headerunderline'>";
sheethtml += "&nbsp;</td><td colspan='2'>&nbsp;</td><td class='colspacer'>&nbsp;</td><td>&nbsp;</td></tr>";
sheethtml += "<tr><td colspan='3' class='label rowspacer'>Student Signature</td><td>&nbsp;</td>";
sheethtml += "<td colspan='3' class='label rowspacer'>Date</td><td colspan='2'>&nbsp;</td><td class='colspacer'>&nbsp;</td>";
sheethtml += "<td>&nbsp;</td></tr><tr><td colspan='5' class='inputlabel'>Note: The Following Requirements Apply:</td>";
sheethtml += "<td>&nbsp;</td><td colspan='3' class='headerunderline'>&nbsp;</td><td class='colspacer'>&nbsp;</td><td>&nbsp;</td>";
sheethtml += benchmarks;

document.write(sheethtml);

}

// test timeString function
// alert("the time is " + timeString( prompt("enter hours:", 18), prompt("enter minutes:", 5 )));

/*function minutesZero(minutes){
	return minutes>9?minutes:("0"+minutes);
}*/
 function minutesZero(minutes){
 if (minutes<29){
	 minutes="00";
	 }
if (minutes>=30){
	 minutes=30;
	 }
return minutes;
  }

// 	timestring will return the string for the hour sent changed to standard 12 hour clock
//		correct  minutes and am/pm concatenated
function timeString(hours, minutes){
	var meridian = hours < 12 ? "am" : ( hours==24 ? "am" : "pm" );
	return ( hours>12 ? (hours-12) : hours ) + ":" + minutesZero(minutes) + meridian;
	
}

function testEOMonth(){
	today.setMonth(parseInt(prompt("Enter the month number:", 0)));
	today.setDate(parseInt(prompt("Enter the date:", 24)));
	var findTheLast = new Date(today);
	var stillthismonth = true;
	var thismonth = today.getMonth();
	while( stillthismonth ){
		stillthismonth = thismonth == findTheLast.getMonth() ? true : false;
		alert("stillThisMonth: " + stillthismonth);
		if(stillthismonth) findTheLast.setTime(findTheLast.getTime()+ADAY);		
		else findTheLast.setTime(findTheLast.getTime()-ADAY);
		alert("ThisMonth: " + thismonth + "; Month: " + findTheLast.getMonth() + "; Day: " + findTheLast.getDate());
	}
	
	setStartDate(today.getDay(), today.getHours()-1);
	alert("the last day of the month is " + findTheLast.getDate() + "; startString: "+ startString + "; starttime: " + starttime + "; endString: " + endString + "; endtime: "+ endtime);
	
	
}

// testSSD() tests the setStartDate function by confirming 
// 		is today the end date
//		is the time before class
function testSSD(){
	if( confirm("Is today the end date?") ){
		if( confirm("Is the time before class starts?") ){
			setStartDate(today.getDay(), today.getHours()+1);
		} 
		else setStartDate(today.getDay(), today.getHours()-1);
	}
	else setStartDate( prompt("Enter day number of startString:", 1), today.getHours()-1 );
	alert("startString: "+ startString + "; starttime: " + starttime + "; endString: " + endString + "; endtime: "+ endtime);
	
}

function setSheetSelects(start){

	generic = document.getElementById("genericselect");
	generic.style.visibility = "hidden";
	specific = document.getElementById("weekselect");
	specific.style.visibility = "visible";
		
	//set date string for this week's lab sheet
	document.sheetform.currentweek.value = (start.getMonth()+1) + "/" + start.getDate() + "/" + start.getFullYear();
	
	//set date string for next week's lab sheet
	var next = new Date();
	next.setTime(start.getTime()+AWEEK);
	document.sheetform.nextweek.value = (next.getMonth()+1) + "/" + next.getDate() + "/" + next.getFullYear();
	
	//set date string for last week's lab sheet
	var last = new Date();
	last.setTime(start.getTime()-AWEEK);
	document.sheetform.lastweek.value = (last.getMonth()+1) + "/" + last.getDate() + "/" + last.getFullYear();
	
}

//  setStartDate(startday, classstart) takes the number of start day of a lab week and the time that the class starts
//    and returns the date object of the last occurance of that day. Startday must be an index SUNDAY=0; MONDAY=1 ...

function setStartDate( startday, classstart ){

    if(startday != "") document.cookie="startday=" + escape(startday) + ";expires=" + expiration;	
    if(classstart != "") document.cookie="classstart=" + escape(classstart) + ";expires=" + expiration;		
	
	setDue(startday);
	
//	alert("Today is: " + today.getDay() + "; startday is: " + startday + "; hours: " + today.getHours() + ";  classstart: " + classstart);
	var startDate = new Date();
	var endDate = new Date();

	classstart>=18?startDate.setHours(classstart + 3):startDate.setHours(classstart + 4);

	endtime = timeString( classstart , 0 );
	if(classstart==17){
		endtime="5:30pm";
	}
	if(classstart==16){
		endtime="5:00pm";
	}
	starttime = timeString( startDate.getHours() , 30 );
	
	startDate.setMinutes(30);
	startDate.setSeconds(0);
	startDate.setMilliseconds(0);
	
	//  if today is the day due for the lab sheet
	//  check to see if we need a sheet for the previous
	//  or following week
	if(today.getDay() == startday){
		
	  //  if the time is before class, sheet is for the previous week
	  if(today.getHours() < classstart ){
		  startDate.setTime(startDate.getTime()-AWEEK);
	  }
	  else startDate.setTime(today.getTime());

	}
	
	//  if today is not the day due, count backwards to get the startString
	else {
		while ( startDate.getDay() != startday ) {
//			alert("startday: " + startday + "; startDate.getDay(): " + startDate.getDay() );
			startDate.setTime(startDate.getTime() - ADAY);
//			alert("startday: " + startday + "; startString: " + startString );			
		}
		
	}
	
//	setSheetSelects(startDate);

	endDate.setTime(startDate.getTime()+AWEEK);
	endString = (endDate.getMonth()+1) + "/" + endDate.getDate() + "/" + endDate.getFullYear();
	
	var tempDate = new Date(startDate);
	startString = (tempDate.getMonth()+1) + "/" + tempDate.getDate() + "/" + tempDate.getFullYear();
	var tempString = startString;
	
	do{
		tempString = (tempDate.getMonth()+1) + "/" + tempDate.getDate() + "/" + tempDate.getFullYear();
		dateArray[tempDate.getDay()] = tempString;
		tempDate.setTime(tempDate.getTime()+ADAY);
//		alert(tempString + "; " + endString);
	}while(tempString != endString)
}

function getLabSheet(){
	studentname = document.sheetform.name.value;
	if(studentname != "") document.cookie="studentname=" + escape(studentname) + ";expires=" + expiration;
	else deleteCookie("studentname");

	instructorname = document.sheetform.instructor.options[document.sheetform.instructor.selectedIndex].value;
	if(instructorname != "") document.cookie="instructor=" + escape(instructorname) + ";expires=" + expiration;
	else deleteCookie("instructor");
	
	classname = document.sheetform.classcode.options[document.sheetform.classcode.selectedIndex].value;
	if(classname != "") document.cookie="classname=" + escape(classname) + ";expires=" + expiration; 
	else deleteCookie("classname");
	
	if(starttime ==	""){
		deleteCookie("startday");
		deleteCookie("classstart");
	}
	for(i=0;i<document.sheetform.online.length;i++){
			if(document.sheetform.online[i].checked){
				onlinego = document.sheetform.online[i].value;
				document.cookie="onlinego=" + escape(onlinego) + ";expires=" + expiration;
			}
		}
	
//	printcookies();
	
	openSheet();
	
/*
alert("studentname: " + studentname + "; instructorname: " + instructorname + "; classname: " + classname + "; startString: "+ startString + "; starttime: " + starttime + "; endString: " + endString + "; endtime: "+ endtime);
*/	
}

