var month_names=new
	Array('January','February','March','April','May','June','July','August','September','October','November','December'
	,'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec');

var month_days=new Array(31,28,31,30,31,30,31,31,30,31,30,31);

var ONE_DAY = 1000 * 60 * 60 * 24;

var today = new Date();

function mark_dates( first_d, last_d, on, off ) 
{
	now = new Date();
	first1 = new Date(first_d);
	last1  = new Date(last_d);
	text = ( first1 <= now && now <= last1) ? on : off;
	document.write( text );
}

//
// Convert 24hr time into 12 hr time and append am or pm
//
function make_time( when )
{
	var hour = when.getHours();
	ampm = (hour >= 1 && hour <= 12) ? "am" : "pm";
	hour %= 12;
	hour = (hour == 0) ? 12 : hour;
	return hour + ':' + (when.getMinutes()<10 ? '0':'')+ when.getMinutes() + ampm;
}

//
// Based on starting date, and number of days
//  ...prepare a string representing the starting and ending date (if not same as start)
//  Ex:  Sept 7,  Dec 2-4,  Oct 29-11/4
//
function date_range( s_date, days) 
{
	if( days == 0)
	{	d_string = 'TBD';}
	else 
	{	d_string = month_names[12 + s_date.getMonth() ] + ' ' + s_date.getDate();
		if( days > 1)
		 with(s_date){
		 	e_date = getDate() + days -1;
		 	e_month = '';
		 	if( e_date > month_days[getMonth()] ) {
		 		e_month = (getMonth()+2)+'/';
		 		e_date -= month_days[getMonth()];
		 	}
			d_string += '-' + e_month + e_date;
		}
	}
	return d_string;
}

//
// Given the 'calendar' array  return a string describing the event on that date
//   If there is an HMTL link, then surround the description with an <a href...> and </a> tags
//   If there is a hover title, include that also.
//   Finally, if a start or stop time exists...include that also.
//     ex:  "Some Event",  "Some Event - 4:30am to 5:00"
//
function date_what( calendar, idx, s_date, e_date, l_class )
{
		what = calendar[idx+0];
		if( calendar[idx + 5].length > 0 ) {
			aclass = ( s_date <= today && today <= e_date) ? 'backblock' : l_class ;
			what = '<a href="' + calendar[idx + 5] + '" title="' + calendar[idx + 6] + '" class="'+ aclass + '" >'
				+ what + '</a>';
			}
		if( s_date.getHours() != 0 )
			what += ' - ' + make_time(s_date );
		if( calendar[idx + 4].length > 0 )
			what += ' to ' + calendar[idx + 4];
		return what;
}

//
// Calendar display for Full Calendar page
//
function full_calendar( calendar )
{
	var this_month = 13;
	var color = '';
	var e_date = new Date();
	for(idx = 0; idx < calendar.length; idx += 7)
	{
		var s_date = new Date( calendar[idx + 1] + " " + calendar[idx + 3] );
		var days = calendar[idx + 2];
		e_date.setTime( s_date.getTime() + (days-1)*ONE_DAY );

		if( s_date.getMonth() != this_month)
		{	this_month = s_date.getMonth();
			an_str = ( this_month == today.getMonth()) ? '<a name="thisMonth">&bull;</a>' : '';
			document.write('<tr valign="TOP" bgcolor="#C5CAD2">'
			 +'<td class="boldblue" colspan="2">' + an_str + month_names[this_month] + 
			 ((this_month == 0) ? ' ' + s_date.getFullYear() : '') + '</td></tr>');
		}
		
		d_string = date_range(s_date, days);
		var what=  date_what( calendar,idx, s_date, e_date, 'reglink');

		document.write('<tr valign="TOP"' + color + '><td class=boldblue>' + d_string + '</td>');
		document.write('<td>' + what + '</td></tr>');
		color = (color.length) ? '' : ' bgcolor="#F2F2F2"';
	}
}

//
// Calendar display for home page
//
function home_calendar( calendar, early, late )
{
	var now = new Date();
	var then = new Date();
	var e_date = new Date();
	now.setTime ( now.getTime() - early*ONE_DAY);		// and xx days in past
	then.setTime( now.getTime() + late*ONE_DAY);		// Display range from yy days in future
	
	var lines=0;
	for(idx = 0; idx < calendar.length && lines < 30; idx += 7)
	{
		days = calendar[idx + 2];
		s_date = new Date( calendar[idx + 1]  + " " + calendar[idx + 3]);
		e_date.setTime( s_date.getTime() + (days-1)*ONE_DAY );

		if( s_date < now && e_date < now)	continue;
//		if( s_date > then)	break;
		
		calendar[idx + 4] = '';
		d_string = date_range(s_date, days);
		what=  date_what( calendar,idx, s_date, e_date, 'blue_italic_9pt');
		
		document.write('<span class="blue_italic_9pt">' + d_string);
		document.write(' - <span class="blue_italic_9pt">' + what + '</span><br><br>');
		chars = d_string.length + what.length + 5;
		lines += 1 + Math.floor((chars + 27)/28);
	}


//	<span class="smallboldblue">&raquo;</span> <span class="smallblue">Nov 1-4</span><br>						
//	<span class="small">Girl Scouts Used Book Drive</span><br><br>
}

// Display different text based on current date
function mark_dates( first_d, last_d, on_txt, off_txt ) 
	{
		now = new Date();
		first1 = new Date(first_d);
		last1  = new Date(last_d);
		text = ( first1 <= now && now <= last1) ? on_txt : off_txt;
		document.write( text );
	//	document.write( first1, now, last1);
	}


;