// Provincial Health Services Authority - IMITS Web Operations, 2010

//	Returns number of days away.
//		0 if on the day
//		Negative if after the day
function getDaysAway(year, month, day)
{
	var today = new Date();
	month--;
	var event = new Date(year, month, day);
	return Math.ceil((event.getTime()-today.getTime())/(1000*60*60*24))
}

//	Returns text for a countdown before the event ("30 days"), 
//		or a message during the event ("On Now!"), 
//		or a message after the event ("Over")
//	Example for an event starting on May 27th, 2010, that is happening for 10 days:
//		returnDaysText(2010, 5, 27, 10, "days", "day", "on now!", "over");
//		Returns: 
//			"20 days" 	20 days before the event
//			"1 day" 	1 day before the event
//			"on now!" 	during the event
//			"over" 		after the event has ended
function returnDaysText(year, month, day, duration, unitPlural, unitSingular, textDuring, textAfter)
{
	duration--;
	
	var diff = getDaysAway(year, month, day);
	
	if (diff <= 0) // if the date is passed, or is during
	{
		diff *= (-1); // make it positive to compare with the duration
		if(diff <= duration)
		{
			return (textDuring);	
		} else {
			return (textAfter);
		}
	} else { // diff > 0
		var dayText = (diff == 1)? unitSingular : unitPlural
		return (diff +" "+ dayText);
	}
}
