/*	JCalendar	Created by Jameson Bennett	completely javascript driven calendar*///custom include statementfunction include(theurl){	document.write('<scr' + 'ipt type="text/javascript" src="'+ theurl +'"><\/scr' + 'ipt>');}//month data structure, used to populate for each monthfunction MonthData(m, y){	this.month = m;	this.year = y;		this.news = new Array();	this.news_url = new Array();	this.news_body = new Array();	this.news_image = new Array();		this.events = new Array();	this.events_url = new Array();	this.events_body = new Array();	this.events_image = new Array();}//JCalendar definitionfunction JCalendar(){	//----------------------------------------------------------------------	//-------------------VARIABLES -----------------------------------------	//----------------------------------------------------------------------	//global arrays	news = new Array();	events = new Array();		//holds all the month datas loaded in	this.monthDatas = new Array();		//constants	this.daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];	this.cal_months = ['January','February','March','April','May','June','July','August','September','October','November','December'];	this.cal_days = ['S', 'M', 'T', 'W', 'T', 'F', 'S']	//initial variable declaration	this.year = 2000;	this.month = 1;	this.day = 1;	this.showyear = 2000;	this.showmonth = 1;	this.showday = 1;	this.srcroot = "../";		//----------------------------------------------------------------------	//-------------------FUNCTIONS -----------------------------------------	//----------------------------------------------------------------------		//----------------------------------------------------------------------	//-------------------INIT      -----------------------------------------	//----------------------------------------------------------------------	this.init = function(y, m, d, srcrt)	{		this.setMonth(m);		this.setYear(y);		this.setDay(d);		this.setSourceRoot(srcrt);		this.populateCurrentMonthData(m, y);		this.populatePastMonthsData(3, m, y);		this.populateFutureMonthsData(3, m, y);	}		this.showdate = function(y, m, d)	{		this.showyear = y;		this.showmonth = m;		this.showday = d;		this.populateCurrentMonthData(m, y);	}		//----------------------------------------------------------------------	//-------------------GET / SET -----------------------------------------	//----------------------------------------------------------------------	this.addMonthData = function(md)	{		//alert("adding month data: " + md.month);		var found = false;		for(var mnths in this.monthDatas)		{			if((this.monthDatas[mnths].month == md.month) && (this.monthDatas[mnths].year == md.year))			{				found = true;			}		}		if(!found)		{			this.monthDatas.push(md);		}	}		this.setYear = function(y)	{	this.year = y;	}		this.setMonth = function(m)	{	this.month = m;	}		this.setDay = function(d)	{	this.day = d;	}		this.setSourceRoot = function(sr)	{		this.srcroot = sr;	}		//----------------------------------------------------------------------	//-------------------WRITERS   -----------------------------------------	//----------------------------------------------------------------------	this.writeCalendarBody = function(d, m, y)	{		if(d > 0)		{						this.writeDaysNewsAndEvents(d, m, y);		}		else		{			//document.write('<div class="section_title">IARC Month News and Events Calendar</div>');			//document.write('<br>');			this.writeMonthsNewsAndEvents(this.showmonth, this.showyear);		}	}			//writes the news and events for a particular month just date and headlines as links	this.writeMonthsNewsAndEvents = function(m, y)	{		var thismonth = this.findMonthData(m, y);		var txt =  '<div class="section_title">' + this.cal_months[m-1] + ', ' + y + '</div>';		txt += ('<br>');		if(thismonth)		{									var n ="";			for(var d=0; d<32; d++){								if(thismonth.news[d])				{					n += ('<div class="news_text">'+ this.getLinkString(y,m,d) + 	 this.cal_months[m-1] + ' ' + d + ': ' + thismonth.news[d] + '</a></div>');					n += ('<br>');				}			}			if(n)			{				txt += ('<div>News:</div>' + n);				txt += ('<br>');			}									var e="";						for(var d=0; d<32; d++)			{								if(thismonth.events[d])				{					e += ('<div class="event_text">'+	this.getLinkString(y,m,d) + this.cal_months[m-1] + ' ' + d + ': ' + thismonth.events[d] + '</a></div>');					e += ('<br>');				}			}				if(e)			{				txt += ('<div>Events:</div>' + e);			}						if(!n && !e)			{				txt+="No news or events for this month.";			}		}		else txt += ('No calendar data available for '+  this.cal_months[m-1] + ', ' + y);				document.write(txt);	}		//call to write the passed days news and events	this.writeDaysNewsAndEvents = function(d, m, y)	{		var thismonth = this.findMonthData(m, y);		if(thismonth)		{			document.write('<div class="section_title">'+  this.cal_months[m-1] + ' '  + d + ', ' + y + '</div>');			document.write('<br>');			if(thismonth.news[d])			{				document.write('<div class="bodyhilite">News: <br>' + thismonth.news[d] + '</div>');								if(thismonth.news_url[d])				{					document.write('<br>');					document.write('<div class="news_url">url: <a href="' + thismonth.news_url[d] + '">' + thismonth.news_url[d] + '<a></div>');				}				if(thismonth.news_body[d])				{					document.write('<br>');					document.write('<div>' + thismonth.news_body[d] + '</div>');					document.write('<br>');				}				document.write('<br>');			}						if(thismonth.events[d])			{				document.write('<div class="bodyhilite">Events: <br>' + thismonth.events[d] + '</div>');				if(thismonth.events_url[d])				{					document.write('<br>');					document.write('<div class="news_url">url: <a href="' + thismonth.events_url[d] + '">' + thismonth.events_url[d] + '</a></div>');				}				if(thismonth.events_body[d])				{					document.write('<br>');					document.write('<div>' + thismonth.events_body[d] + '</div>');					document.write('<br>');				}			}					}		else document.write('No calendar data available for '+  this.cal_months[m-1] + ', ' + y);	}		//writes the latest news in reference to the current year month day	this.writeLatestNews = function(howmany)	{				var counter = 0;				document.write('<div id="latestnews">');		document.write('<table>');		for(var mth in this.monthDatas)		{			if(this.monthDatas[mth].month <= this.month)			{				for(var n = 31; n > 0; n--)				{										if( (counter < howmany) &&					   (this.monthDatas[mth].news[n]) &&						   (								(this.monthDatas[mth].month < this.month) ||								((this.monthDatas[mth].month == this.month) && (n <= this.day))							)					   )					{						document.write('<tr><td class = "news_date"> ');						document.write(this.cal_months[this.monthDatas[mth].month-1]);						document.write(' ');						document.write(n);						document.write('</td><tr> ');						document.write('<tr><td class = "news_text">');						document.write(this.getLinkString(this.monthDatas[mth].year,this.monthDatas[mth].month,n) + this.monthDatas[mth].news[n] + '</a>');						document.write('<br><br></td><tr> ');						counter++;					}				}			}		}		document.write('</table>');		document.write('</div>');	}		//call to write 'howmany' upcoming events from the current ymd	this.writeUpcomingEvents = function(howmany){		//load in the events		//iterate from this date fwd		var counter = 0;				document.write('<div id="upcomingevents">');		document.write('<table>');				for(var mth in this.monthDatas)		{			if(this.monthDatas[mth].month >= this.month)			{				for(var evts in this.monthDatas[mth].events)				{					if(counter < howmany)					{						var monthNum = this.monthDatas[mth].month;						if( (monthNum > this.month)||							((monthNum == this.month) && (evts > this.day)) )						{							document.write('<tr><td class = "event_date"> ');							document.write(this.cal_months[this.monthDatas[mth].month-1]);							document.write(' ');							document.write(evts);							document.write('</td><tr> ');							document.write('<tr><td class = "event_text">');							document.write(this.getLinkString(this.monthDatas[mth].year,this.monthDatas[mth].month,evts) + this.monthDatas[mth].events[evts] + '</a>');							document.write('<br><br></td><tr> ');							counter++;						}					}				}			}		}		document.write('</table>');		document.write('</div>');	}	//call to write the calendar into the document	this.writeCalendar = function(m, y)	{		document.write(this.buildCalendar(m, y));	}		//returns a text string of the built calendar	this.buildCalendar = function(m, y)	{		var mData = this.findMonthData(m, y);		var styleMain = "cal_main";		var styleHead = "cal_month";		var styleDayOfWeek = "cal_daysofweek";		var styleDay = "cal_days";		var styleToday = "cal_today";				var theDate = new Date(y, m-1, 1);		theDate.od=theDate.getDay()+1;				//check for leap year		if(this.isLeapYear(theDate))	daysInMonth[1] =29;						var todaydate=new Date();		var scanfortoday=(y==todaydate.getFullYear() && m==todaydate.getMonth()+1)? todaydate.getDate() : 0;				//month title		var t='<div id="jcalendar" class="'+styleMain+'"><table class="'+styleMain+'" cols="7"><tr>';		//last month link		t+='<td class="'+styleHead+'"><a href="' + gSITEROOT + '/news/index.html?cm=' + this.getLastMonth(m, y) +'&cy=' + this.getLastYear(m, y) +'"><</a></td>';		//print current month		t+='<td colspan="5" class="'+styleHead+'">'+this.cal_months[m-1]+'  '+y+'</td>';		//next month link		t+='<td class="'+styleHead+'"><a href="' + gSITEROOT + '/news/index.html?cm=' + this.getNextMonth(m, y) +'&cy=' + this.getNextYear(m, y) +'">></a></td>';				t+='</tr><tr>';				//days title		for(s=0;s<7;s++){			t+='<td class="'+styleDayOfWeek+'">'+this.cal_days[s]+'</td>';		}				t+='</tr><tr>';					//run thru each cell		for(i=1;i<=42;i++){			var x= -1;						if((i-theDate.od>=0)&&(i-theDate.od<this.daysInMonth[m-1]))			{				x = i-theDate.od+1;			}						if (x > -1)			{				//if we have something in the day array at pos x				var theNews=0;				var theEvent=0;				if(mData)				{ 					var theNews=mData.news[x];					var theEvent=mData.events[x];				}													t+='<td class="';				if((theNews)&&(theEvent)){					t+='cal_newsevents';					t+='" title="NEWS: ' + theNews + '  \nEVENTS: ' + theEvent;					x='<a href="'+ gSITEROOT +'/news/index.html?cd=' + x + '&cm=' + m + '&cy=' + y + '">'+x+'</a>';								}else if(theNews){					t+='cal_news';					t+='" title="NEWS: ' + theNews;					x='<a href="'+ gSITEROOT +'/news/index.html?cd=' + x + '&cm=' + m + '&cy=' + y + '">'+x+'</a>';						}else if(theEvent){					t+='cal_events';					t+='" title="EVENTS: ' + theEvent;					x='<a href="'+ gSITEROOT +'/news/index.html?cd=' + x + '&cm=' + m + '&cy=' + y + '">'+x+'</a>';						}else{					t+= styleDay;				}								t+='">'+x+'</td>';			}			else if (x == -1) //default to nbsp			{							t+='<td class="'+styleDay+'">&nbsp;</td>';			}						if( ((i)%7==0) && (i<36) )			{					t+='</tr><tr>';			}		}			return t+='</tr></table></div>';	}				//----------------------------------------------------------------------	//-------------------UTILITY   -----------------------------------------	//----------------------------------------------------------------------	this.isLeapYear = function(dt)	{		if(((dt.getFullYear()%100!=0)&&(dt.getFullYear()%4==0))||(dt.getFullYear()%400==0))			return true;		else return false;	}		//assuming month incrementing and decrementing	this.getNextMonth = function(m, y)	{		if(m > 11)			return 1		else return m-(-1);	}	this.getLastMonth = function(m, y)	{		if (m == 1)			return 12;		else return m-1;	}	this.getNextYear = function(m, y)	{		if(m > 11)			return y-(-1);		else return y;		}	this.getLastYear = function(m, y)	{		if (m == 1)			return y-1;		else return y;	}				//returns the month data struct if it is available, if not returns a 0	this.findMonthData = function(m, y)	{		for(var thismonth in this.monthDatas)		{			if((this.monthDatas[thismonth].month ==m)&&(this.monthDatas[thismonth].year == y))				return this.monthDatas[thismonth];		}		//not available!		return 0;	}		//getLinkString returns a preformatted anchor tag hreffing the days article	this.getLinkString = function(y,m,d)	{		return '<a href="'+ gSITEROOT +'/news/index.html?cd=' + d + '&cm=' + m + '&cy=' + y + '">';	}			//----------------------------------------------------------------------	//-------------------DATA LOAD -----------------------------------------	//----------------------------------------------------------------------	//fill in the global news and events arrays with the data	this.populateMonthData = function(m, y){		//md.init();		src = this.srcroot + this.cal_months[m-1] + y + '/data.js';		document.write('<script type="text/javascript" src="' + src + '"><\/script>');		//alert("m: " + m+ "  source:" +src);	}		//populates (includes thru js trick) past months data from the passed month and year	this.populatePastMonthsData = function(numMonthsPast, m, y){		this.pastMonthsDataArray = [];		for(var x=0; x<numMonthsPast; x++)		{			var lm = this.getLastMonth(m-x, y);			var ly = this.getLastYear(m-x, y);			this.populateMonthData(lm, ly);		}	}		//populates (includes thru js trick) future months data from the passed month and year	this.populateFutureMonthsData = function(numMonths, m, y){		this.futureMonthsDataArray = [];		for(var x=0; x<numMonths; x++)		{			var nm = this.getNextMonth(m+x, y);			var ny = this.getNextYear(m+x, y);			this.populateMonthData(nm, ny);		}	}			//populates the data for the current month and year	this.populateCurrentMonthData = function(m, y){		this.populateMonthData(m, y);	}		//----------------------------------------------------------------------	//-------------------END JCalendar--------------------------------------	//----------------------------------------------------------------------}