﻿/***************************************************************************************	Calendar JavaScript			// Varibales			thisDate: Tracks current date being written in calendar			wordMonth: Array that stores name of month			today: Date object to store the current date			todaysDay: Stores the current day number 1-7			todaysDate: Stores the current numeric date within the month			todaysMonth: Stores the current month 1-12			todaysYear: Stores the current year			monthNum: Tracks the current month being displayed			yearNum: Tracks the current year being displayed			firstDate: Object Storing the first day of the current month			firstDay: Tracks the day number 1-7 of the first day of the current month  			lastDate: Tracks the last date of the current month			direction: Inputs the direction (next, prev, or return) the calendar should flip				// Functions			changeMonth(): Flips to next, previous, or current month depending on "direction" input			createCalendar(): Renders the calander into the page with links for each to fill the date form filds above.			setDate(): Sets the form date fields based on data passed to it from createCalendar()			***************************************************************************************/	var thisDate = 1;	var wordMonth = new Array("january","february","march","april","may","june","july","august","september","october","november","december");	var today = new Date();	var todaysDay = today.getDay() + 1;	var todaysDate = today.getDate();	var todaysMonth = today.getUTCMonth() + 1;	var todaysYear = today.getFullYear();	var monthNum = todaysMonth;	var yearNum = todaysYear;	var firstDate = new Date(String(monthNum)+"/1/"+String(yearNum));	var firstDay = firstDate.getUTCDay();	var lastDate = new Date(String(monthNum+1)+"/0/"+String(yearNum));	var numbDays;	function changeMonth(direction) {		if (direction == "prev") monthNum--;		else if (direction == "next") monthNum++;		else  if (direction == "return") { 			monthNum = todaysMonth;			yearNum = todaysYear;		}		if (monthNum == 0) {			monthNum = 12;			yearNum--;		}		else if (monthNum == 13) {			monthNum = 1;			yearNum++		}		lastDate = new Date(String(monthNum+1)+"/0/"+String(yearNum));		//numbDays = lastDate.getDate();		var month = [31,28,31,30,31,30,31,31,30,31,30,31];		numbDays = month[monthNum-1];		firstDate = new Date(String(monthNum)+"/1/"+String(yearNum));		firstDay = firstDate.getDay() + 1;		createCalendar();		return;	}		function createCalendar() {		var writeCalendar = '';		var url = document.location.href;		var urlArr = url.split('/');		var calendarid = urlArr[5];				writeCalendar += '<a class="calControl" onmouseover="window.status=\'Previous Month\';return true" onmouseout="window.status=\'\';return true" href="javascript:changeMonth(\'prev\')"><img src="/graphics/cal_arrow_left.png" alt="Previous Month" border="0" /></a>';		writeCalendar += '<a class="calControl" href="javascript:changeMonth(\'return\')"><img src="/graphics/cal_return.png" alt="Return to Current Month" border="0" /></a>';		writeCalendar += '<a class="calControl" onmouseover="window.status=\'Next Month\';return true" onmouseout="window.status=\'\';return true" href="javascript:changeMonth(\'next\')"><img src="/graphics/cal_arrow_right.png" alt="Next Month" border="0" /></a>';				writeCalendar += '<span class="monthShow">';		writeCalendar += wordMonth[monthNum-1] + '&nbsp;&nbsp;';		writeCalendar += yearNum;		writeCalendar += '</span><br style="clear:both" />';				writeCalendar += '<span class="calDay">M</span><span class="calDay">T</span><span class="calDay">W</span><span class="calDay">Th</span><span class="calDay">F</span><span class="calDay">S</span><span class="calDay">S</span>'				var theDay;		var theMonth;				for (var i = 1; i <= 42; i++) {			if ((i==1)|| (i==8)|| (i==15)|| (i==22)|| (i==29)|| (i==36)) {				writeCalendar +=  '<br style="clear:both" />';			}						theDay = (thisDate < 10) ? '0' + thisDate : thisDate;			theMonth = (monthNum < 10) ? '0' + monthNum : monthNum;							if ((thisDate <= numbDays) && (i >= (firstDay-1))) {				if ((thisDate == todaysDate) && (todaysMonth == monthNum) && (todaysYear == yearNum)) {					if(document.getElementById('event-' + yearNum + '-' + theMonth + '-' + theDay) != null) {						writeCalendar += '<a class="calDateToday" style="background-color: #FFDDDD;" onmouseover="javascript:showEvents(\'' + yearNum + '-' + monthNum + '-' + thisDate + '\')" href="/schedule/daily/' + calendarid + '/' + yearNum + '-' + theMonth + '-' + theDay + '">' + thisDate + '</a>';						//writeCalendar += '<a class="calDateToday" style="background-color: #FFDDDD;" href="javascript:showEvents(\'' + yearNum + '-' + monthNum + '-' + thisDate + '\')">' + thisDate + '</a>';					} else {						writeCalendar += '<a class="calDateToday" onmouseover="javascript:showEvents(\'' + yearNum + '-' + monthNum + '-' + thisDate + '\')" href="javascript:void(0)">' + thisDate + '</a>';						//writeCalendar += '<a class="calDateToday" href="javascript:showEvents(\'' + yearNum + '-' + monthNum + '-' + thisDate + '\')">' + thisDate + '</a>';					}								// Event Date				} else if(document.getElementById('event-' + yearNum + '-' + theMonth + '-' + theDay) != null) {					writeCalendar += '<a class="calDate" style="background-color: #FFDDDD;" onmouseover="javascript:showEvents(\'' + yearNum + '-' + monthNum + '-' + thisDate + '\')" href="/schedule/daily/' + calendarid + '/' + yearNum + '-' + theMonth + '-' + theDay + '">' + thisDate + '</a>';					//writeCalendar += '<a class="calDate" style="background-color: #FFDDDD;" href="javascript:showEvents(\'' + yearNum + '-' + monthNum + '-' + thisDate + '\')">' + thisDate + '</a>';								// Regular Date				} else {					writeCalendar += '<a class="calDate" onmouseover="javascript:showEvents(\'' + yearNum + '-' + monthNum + '-' + thisDate + '\')" href="javascript:void(0)">' + thisDate + '</a>';					//writeCalendar += '<a class="calDate" href="javascript:showEvents(\'' + yearNum + '-' + monthNum + '-' + thisDate + '\')">' + thisDate + '</a>';				}				thisDate++;							} else {				writeCalendar += '<span class="calEmpty">&nbsp;</span>';			}		}				var object=document.getElementById('calendar');		object.innerHTML= writeCalendar;		thisDate = 1;	}	