



function buildCal(m, y, cM, cH, cDW, cD, brdr,evdaytypes,evdaylist){ //evdaylist: not used yet, will allow array of event days to be in index.html and not in this .js file

var eventlist=evdaylist
//First element is months; second is days; 3rd is years, 4th is type (shading color--starts with 1, not 0)

var count; //Jadded (added by Jaime)
var mn=['January','February','March','April','May','June','July','August','September','October','November','December'];
var dim=[31,0,31,30,31,30,31,31,30,31,30,31];

var oD = new Date(y, m-1, 1); //DD replaced line to fix date bug when current day is 31st
oD.od=oD.getDay()+1; //DD replaced line to fix date bug when current day is 31st

var todaydate=new Date() //DD added
var scanfortoday=(y==todaydate.getFullYear() && m==todaydate.getMonth()+1)? todaydate.getDate() : 0 //DD added

dim[1]=(((oD.getFullYear()%100!=0)&&(oD.getFullYear()%4==0))||(oD.getFullYear()%400==0))?29:28;
var t='<div class="'+cM+'"><table class="'+cM+'" cellpadding="1" border="'+brdr+'" cellspacing="0"><tr align="center">';
t+='<td colspan="7" align="center" class="'+cH+'">'+mn[m-1]+' - '+y+'</td></tr><tr align="center">';

var s;

for(s=0;s<7;s++)t+='<td class="'+cDW+'">'+"SMTWTFS".substr(s,1)+'</td>';
t+='</tr><tr align="center">';

var i;

for(i=1;i<=42;i++){
var x=((i-oD.od>=0)&&(i-oD.od<dim[m-1]))? i-oD.od+1 : '&nbsp;';

var eventday=0 //is set to array position of date
for (count in eventlist)
{
if ((eventlist[count][0])==m && (eventlist[count][1])==x && (eventlist[count][2])==y)
eventday=1-(-count)//must add 1 here so that it shows up later with !=0. Also must do double negative to convert count to a number, not a string.
}

//var itstoday=0;  //don't need any more?
if (x==scanfortoday) //DD added
	x='<span id="today">'+x+'</span>'; //DD added

if (eventday!=0)
{
	switch (eventlist[eventday-1][3]) //4th element in array, indicates type of day
	{
	case 1:
	t+='<td class="'+evdaytypes[0]+'">'+x+'</td>'; 
	break;

	case 2:
	t+='<td class="'+evdaytypes[1]+'">'+x+'</td>'; //I only have one type so far. Eventually, the "evday" in this statement will be changed. =D
	break;

	default:
	//this shouldn't happen
	}
}
else
{
	t+='<td class="'+cD+'">'+x+'</td>';
}


if(((i)%7==0)&&(i<36))t+='</tr><tr align="center">';
}
return t+='</tr></table></div>';


}



function printevents(month,width,txt)
{

var c

var indx=-1
for (c in txt)
{
if (month == txt[c][0])
indx=c
}

var t="<table width=" + width + ">" //var t:the total that will be doc-written

t+="<tr><th align=\"left\" style=\"width:13%\">Day</th><th align=\"right\"  style=\"width:15%\" >Time</th><th align=\"right\"  style=\"width:80%\">Service\/Event</th></tr>"

for (c in txt[indx])
{
if (c!=0)
{
t+="<tr>"

t+="<td align=\"left\">"
t+=txt[indx][c][0]
t+="</td>"

t+="<td align=\"right\">"
t+=txt[indx][c][1]
t+="</td>"

if (txt[indx][c].length == 4)
{
	divisionindicator = txt[indx][c][3]
}
else
{
	divisionindicator=Math.floor((txt[indx][c][2].length)/70)
}

if (divisionindicator > 0)
{
	t+="<td  rowspan=\""
	t+=(1+divisionindicator)
	t+="\" align=\"right\">"
	t+=txt[indx][c][2]
	t+="</td>"

	t+="</tr>"
	
	for (coun = 0; coun < divisionindicator; coun++)
	{
		t+="<tr><td>&nbsp;</td></tr>" //make empty spaces because of the large description
	}
}

else
{
	t+="<td align=\"right\">"
	t+=txt[indx][c][2]
	t+="</td>"

	t+="</tr>"
}
}
}

t+="</table>"
document.write(t)
}

