// lunch_main(lunch_list)
// 
// Copyright Throstur Thorsteinsson, updated by Joe MacGregor, 2004.

function lunch_main(lunch_list) {

todays_date = new Date();
ms_day = 24 * 60 * 60 * 1000; // number of ms per day
days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

i = 0;

while (lunch_list[i] != "End") {

	next_lunch = new Date(lunch_list[i].substring(0, lunch_list[i].lastIndexOf(":")));
	days_left = (next_lunch.getTime() - todays_date.getTime()) / ms_day;
	days_left = Math.round(10 * days_left) / 10;

	if (days_left < 31 && days_left > -2){

		document.write("<FONT color=\"Blue\"><B>"+days[next_lunch.getDay()]+" "+next_lunch.getDate()+ " "+months[next_lunch.getMonth()]+":</B></FONT>");

  		topic = lunch_list[i].substring(lunch_list[i].lastIndexOf(":") + 1, lunch_list[i].lastIndexOf("$"));

   		if ((lunch_list[i].lastIndexOf("$")+1 == lunch_list[i].lastIndexOf("."))) {
     			document.write("<FONT COLOR=\"Navy\">\t"+"General discussion<BR></FONT>");}
   		else {
     			document.write("<FONT COLOR=\"Black\"><B>\t\""+topic+"\"</B></FONT>");
     			speaker = lunch_list[i].substring(lunch_list[i].lastIndexOf("$") + 1, lunch_list[i].lastIndexOf("."));
     			document.write("&nbsp;&nbsp;<FONT COLOR=\"Red\" FACE=\"Times\"><B>"+speaker+"</B></FONT><hr width=\"80%\" noshade size=\"1\" color=\"#0000FF\">");
   		}

	}
i += 1;

}

if (lunch_list[i] == "End" && days_left < 14) {
	last_lunch = next_lunch.getTime();
  	while (days_left < 13){
		last_lunch += 7 * ms_day;
		soon_lunch = new Date(last_lunch);
		days_left = (last_lunch - todays_date.getTime()) / ms_day;
		days_left = Math.round(10 * days_left) / 10;
		document.write("<FONT COLOR=\"Blue\">"+days[soon_lunch.getDay()]+" "+soon_lunch.getDate()+" "+months[soon_lunch.getMonth()]+":</FONT>");
     		document.write("<FONT COLOR=\"Black\">\t"+"General discussion<BR></FONT>");
	}
}

}

function lunch_all(lunch_list) {

i = 0;

days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

while (lunch_list[i] != "End"){

	next_lunch = new Date(lunch_list[i].substring(0, lunch_list[i].lastIndexOf(":")));
  	topic = lunch_list[i].substring(lunch_list[i].lastIndexOf(":") + 1, lunch_list[i].lastIndexOf("$"));
     	speaker = lunch_list[i].substring(lunch_list[i].lastIndexOf("$") + 1, lunch_list[i].lastIndexOf("."));

  	document.write("<FONT COLOR=\"Blue\"><B>"+days[next_lunch.getDay()]+" "+next_lunch.getDate()+ " "+months[next_lunch.getMonth()]+", "+next_lunch.getYear()+"</B></FONT>");
     	document.write("<BR><B>\t\""+topic+"\"</B></FONT><BR>");
     	document.write("<FONT COLOR=\"Red\" FACE=\"Times\"><B>"+speaker+"</B></FONT><hr width=\"80%\" noshade size=\"1\" color=\"#0000FF\">");
	i += 1;
}

}