/* JavaScript to automatically update
a calendar facility on a web page 

Last modified 19/5/2006
*/

/*

An example of using my code is to write in the HTMl:

<script> 
<!--
event(1,1,2,5,"YOur Calendar Event Here");
-->
</script>

This will output "Your Calendar Event Here", from he 1st of Jan
until the 2nd May. 

The output is formatted to give a line before and after the inputed text.

event_year is the same, expect that you woudl write:

event_year(1,1,2006,2,5,2006,"YOur Calendar Event Here");

to get the event to only be used in 2006. 

If the year is the same for both inputs, then the funcation is the same as
event, (after a few checks, event is called).

Here are the function callings explained a bit more.

event(start day of the month, start month, end day of the month, end month, "The text in speach marks");
event_year(start day of the month, start month, start year, end day of the month, end month, end year, "The text in speach marks");

**************************************************
Remember to put a semi-colon - ; - after each line!
***************************************************

*/

var theDate = new Date();

function event( start_day, start_month, end_day, end_month, String )
{	/*a funcatiuon to check the current date is within the given limits and then pritn the string if it is*/
	
	
	
	if ( (theDate.getMonth() < (start_month-1)))
	{ /* if too early, don't do anything*/
		
		return 1;
	}
	
	
	
	if ( (theDate.getMonth() == (start_month-1)) && (theDate.getDate()>=start_day) )
	{	/*if in the start month, and have passed the start date*/
			
		if ( (theDate.getMonth() < (end_month-1)) )
		{ /*if not gone into the ending month then print*/
			
			document.write(String+"<p>");
			return 1;
		}
		
				
		if ( (theDate.getMonth() == (end_month-1)) && (theDate.getDate() <= end_day) )
		{	/* if in the end month, and have not goen passed the end date, then print*/
			
			document.write(String+"<p>");
			return 1;
		}
	}
	
	if (theDate.getMonth() > (start_month-1))
	{ /* if passed the start month, so into the next month*/
			
		if ( (theDate.getMonth() < (end_month-1)) )
		{ /*if not gone into the ending month then print*/
			
			document.write(String+"<p>");
			return 1;
		}
		
				
		if ( (theDate.getMonth() == (end_month-1)) && (theDate.getDate() <= end_day) )
		{	/* if in the end month, and have not goen passed the end date, then print*/
			
			document.write(String+"<p>");
			return 1;
		}
	}
	
	return 1;
}



function event_year( start_day, start_month, start_year, end_day, end_month, end_year, String )
{ /*a function to check the date is within the given date (year included) and then ouput the string if it is*/	
		
	if ( (theDate.getYear() < (start_year - 1900 )) || (theDate.getYear() > (end_year - 1900 )) )
	{	/*if before the start or after the end, do nothing*/
		
		return 1;
	}
	
	
	if ( (theDate.getYear() == (start_year - 1900 )) && ( ( theDate.getMonth() < (start_month-1) ) || ( (theDate.getMonth() == (start_month-1)) && (theDate.getDate() < start_day))) )
	{ /*if in the year and either before the start month or before the start day, do nothing*/
		
		return 1;
	}
	
		
	if ( (theDate.getDate() > end_day) && (theDate.getMonth() > (end_month-1)) && (theDate.getYear() >= (end_year -1900)) )
	{	/*if passed the date, do nothing*/
		
		return 1;
	}
	
	if ( start_year == end_year)
	{	/*if all in one year*/
		
		event(start_day,start_month,end_day,end_month,String);
		/*if all in the same year, can use event function*/
		return 1;
	}
	
	if ( (theDate.getYear() == (start_year - 1900)))
	{	/*if in the start year (which is not the end year), just check to see if passed date*/
		
		if ( (theDate.getMonth() == (start_month-1)) && (theDate.getDate()>=start_day) )
		{	/*if in the start month, and have passed the start date*/
			
			document.write(String+"<p>");
			return 1;
		}
		
		if ( (theDate.getMonth() > (start_month-1))  )
		{	/* if have passed the start month, and not in end year*/
			
			document.write(String+"<p>");
			return 1;
		}
	} /*end of start year end*/
	
	if ( theDate.getYear() < (end_year - 1900) )
	{	/* if not in the last year, and have passed the start point by previous checks*/
		
		document.write(String+"<p>");
		return 1;
	}
	
	
	
	if ( theDate.getYear() == (end_year-1900) )
	{ /*if in the end year, jsut check to see if passed the end date*/
		
		if ( theDate.getYear() < (end_month - 1) )
		{	/*if in the end year, and not got to end month*/
			
			document.write(String+"<p>");
			return 1;
		}
				
		if ( (theDate.getMonth() == (end_month - 1)) && (theDate.getDate() <= end_day) )
		{ /*if i nthe end month and not passed the end day*/
			
			document.write(String+"<p>");
			return 1;
		}
		
	}
	return 1;
}
