function CalendarOb()
{
	this.m_oDocument = document;

	function show_calendar(the_year, the_month, the_day)
	{
		var img_path = '';
		if(img_path) top.DesktopWindow.img_path = img_path; 
		else img_path = top.DesktopWindow.img_path;
		// set global ptr to this calendar document...
		top.DesktopWindow.currentCalendarDoc = this.m_oDocument;
		// set global ptr to this calendar object...
		top.DesktopWindow.currentCalendarOb = this;

		// force day to be 1 - dont need it to increment when flicking through months
		the_day = 1;

		// if no date passed assume current date
		calendar_now = new Date();

		if (the_year == '') the_year = calendar_now.getFullYear();
		if (the_month == '') the_month = calendar_now.getMonth();
		if (the_day == '') the_day = calendar_now.getDay();

		// Create array of week days and months in a year
		week_days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
		year_months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

		// Define variables and things
		calendar = new Date(the_year, the_month, the_day);

		year = calendar.getFullYear();
		month = calendar.getMonth();
		day = calendar.getDay();
		today = calendar.getDate();

		// calendar starts at 1
		calendar.setDate(1);
		// set the current month
		calendar.setMonth(month);

		// month drop box
		print_month_box = '\
		<div style="display: none; position: absolute; z-index: 9999999; left: 254px; margin-top: 3px; border: solid; border-width: 1px; border-color: #657485; cursor: default;">\
			<table style="border: solid; border-width: 1px;" width="100" bgcolor="#97aece">';

		for (i=0; i < 12; i++)
		{
			if (year_months[i] == year_months[month]) var backgroundColor = "#ffffff";
			else var backgroundColor = "#97aece"
			print_month_box += '\
				<tr onmouseover="this.bgColor=\'#ffffff\';" onmouseout="this.bgColor=\'#97aece\';" onClick="top.DesktopWindow.currentCalendarOb.show_calendar(\''+year+'\',\''+i+'\',\'\',\''+img_path+'\'); getEvents();">\
				<td style="border: solid; border-width: 1px; border-color: '+backgroundColor+'">\
				<font face="Arial" size="2"><b>'+ year_months[i] +'</b></font>\
							</td>\
				</tr>';
		}

		print_month_box += '\
					</table>\
			</div>';

        // year drop box
        print_year_box = '\
        <div style="display: none; position: absolute; z-index: 9999999; left: 329px; margin-top: 3px; border: solid; border-width: 1px; border-color: #657485; cursor: default;" onmouseover="this.style.display = \'inline\';" onmouseout="this.style.display = \'none\';"><span onmouseover="top.DesktopWindow.currentCalendarOb.listYearsObj = this;">\
                <table style="border: solid; border-width: 1px;" width="80" bgcolor="#97aece">\
        <tr><td><div align="center" onmouseout="top.DesktopWindow.scrollagain = false;" onmouseup="top.DesktopWindow.scrollagain = false;" onmousedown="top.DesktopWindow.scrollagain = true; setTimeout(\'top.DesktopWindow.currentCalendarOb.scrollUpforabit(\\\''+year+'\\\',\\\''+month+'\\\')\',0);" style="color: #ffffff; font-size:10px; font-family: Arial; font-weight: bold;">/\\</div></td></tr>';

        for (i=0; i < 7; i++)
        {
                if (year == (list_year+i)) var backgroundColor = "#ffffff";
                else var backgroundColor = "#97aece";
                var list_year = (year-3); // minus 3 years off current year. this will show previous years aswell on list
                print_year_box += '\
                        <tr onmouseover="this.bgColor=\'#ffffff\';" onmouseout="this.bgColor=\'#97aece\'" onClick="top.DesktopWindow.currentCalendarOb.show_calendar(\''+(list_year+i)+'\',\''+(month)+'\',\'\',\''+img_path+'\'); getEvents();">\
                        <td style="border: solid; border-width: 1px; border-color: '+backgroundColor+'">\
                        <font face="Arial" size="2"><b>'+ (list_year+i) +'</b></font>\
                        </td>\
                        </tr>';
        }


        print_year_box += '\
        <tr><td><div align="center" onmousedown="top.DesktopWindow.scrollagain = true; setTimeout(\'top.DesktopWindow.currentCalendarOb.scrollDownforabit(\\\''+year+'\\\',\\\''+month+'\\\')\',0);" style="color: #ffffff; font-size:10px; font-family: Arial; font-weight: bold;">\\/</div></td></tr>\
                </table></span>\
        </div>';

		// Header of Calendar
		print_calendar = '<div><table style="width: 100%; height: 500px;">\
		<tr valign="top">\
		<td>\
			'+ print_month_box  +'\
			'+ print_year_box  +'\
			<table width="100%" border="0">\
			<tr valign="top">\
			<td colspan="7" style="background: #535353; color: #ffffff; font-size: 26px;"><strong><div><span style="float: left; cursor:default" onclick="top.DesktopWindow.currentCalendarOb.show_calendar(\''+year+'\',\''+(month-1)+'\',\'\',\''+img_path+'\'); getEvents();" ondblclick="top.DesktopWindow.currentCalendarOb.show_calendar(\''+year+'\',\''+(month-1)+'\',\'\',\''+img_path+'\');"><span style="left: 8px; height: 18px; width: 20px; border: solid; border-width: 1px;" onmouseover="this.style.borderColor=\'#ffffff\'" onmouseout="this.style.borderColor=\'#ffffff\'"><img style="" src="../images/calendar_left.gif" style="margin-top: 2px;"></span></span><span style="float: left; cursor: default" onclick="top.DesktopWindow.currentCalendarOb.show_calendar(\''+year+'\',\''+(month+1)+'\',\'\',\''+img_path+'\'); getEvents();" ondblclick="top.DesktopWindow.currentCalendarOb.show_calendar(\''+year+'\',\''+(month+1)+'\',\'\',\''+img_path+'\');">&nbsp;<span style="left: 32px; height:18px; width: 20px; border: solid; border-width: 1px;" onmouseover="this.style.borderColor=\'#ffffff\'" onmouseout="this.style.borderColor=\'#ffffff\'"><img src="../images/calendar_right.gif" style="margin-top: 2px;"></span></span><span style="float: left; cursor: default;" onClick="parentNode.parentNode.offsetParent.offsetParent.previousSibling.previousSibling.style.display=\'inline\'; parentNode.parentNode.offsetParent.offsetParent.previousSibling.style.display=\'none\';">&nbsp;<span style="left: 56px; width: 100px; border: solid; border-width: 0px;" onmouseover="" onmouseout="">'+year_months[month]+'</span></span> <span style="float: left; cursor: default;" onClick="parentNode.parentNode.offsetParent.offsetParent.previousSibling.style.display=\'inline\'; parentNode.parentNode.offsetParent.offsetParent.previousSibling.previousSibling.style.display=\'none\';">&nbsp;<span style="left: 160px; width: 40px; border: solid; border-width: 0px;" onmouseover="" onmouseout="">'+year+'</span></strong></span></div><div style="position: absolute; margin-left: 100px; margin-top: 10px;"><FORM name="postDetails" action="../search/search_results.php" method="get"><input type="hidden" name="CI_CH_ORGID_11213" value="on"><span style="color: #ffffff; font-size: 18px;">Search </span><INPUT size="15" name="key_words"><INPUT class="button" type="submit" value="Go"></div><div id="newEvent" style="display: none; float:right; font-size: 14px; margin-top: 10px; margin-right: 5px; color: #ffffff;" onclick="">New Event<a href="event.php"><img src="../images/add_32x32.gif" border="0" /></a></div></td>\
			</tr>\
			<tr>';

		// print days of the week
		for (i=0; i < 7; i++)
		{
			print_calendar += '<td style="background: #b5cbef; text-align: center; height: 25px; cursor: default; font-weight: bold;">'+week_days[i]+'</td>';
		}
		print_calendar += '</tr>\
		<tr>';
		// Blank out before 1
		for (i=0; i < calendar.getDay(); i++)
		{
			print_calendar += '<td style="background: #ffffd6">'+' '+ '</td>';
		}

		for (i=0; i < 31; i++)
		{
			if (calendar.getDate() > i) show_next_day = calendar.getDay();
			if (show_next_day == 0) print_calendar += '<tr>'; // start a new row for first week day
			if (show_next_day != 7) var theday = calendar.getDate(); 
			if((i+1)==theday)
			{
				// get milliseconds since 1970 of each day in the loop
				var selected_full_date = new Date(year,month,theday);
				var selected_date_secs = selected_full_date.getTime();

				// convert interger to string and find out if 1 digit, if it is add 0
				theday = theday + '';
				if (theday.length == 1) theday = '0' + theday;

				// Convert month to string to add 0 if month is single digit
				var the_month = month + 1;
				var the_month = the_month + '';
				if (the_month.length == 1) the_month = '0' + the_month;
				print_calendar += '<td valign="top" onmouseover="this.style.backgroundColor=\'#dee3ef\'" onmouseout="this.style.backgroundColor=\'#fff7bd\'" style="cursor: default; background: #fff7bd; height: 82px; width: 131px;" onClick="">\
				<font face="Arial" size="2" color="#000000">'+theday+'</font>\
				<br />\
				<span id="date'+(parseInt(((selected_date_secs)/86400000)+0.5,10))+'" ></span>\
				</td>';
			}
			if (show_next_day == 7) print_calendar += '</tr>'; // end the row for week
			calendar.setDate(calendar.getDate()+1);
		} 
		print_calendar += '</table>\
			</td>\
			</tr>\
			</table></div>';
			document.getElementById('calendarLoc').innerHTML = print_calendar;

	}

	this.show_calendar = show_calendar;
}
