<!--
	/*
		Program: Calendar.js
		Programmer: Marcos Gonzalez
		Date Written: March 3, 2001
		Description:  This program generates a popup calendar window.  The calendar is dynamic; you can
			select the month and or year.  The calendar style can be changed from standard to european.
		  On the standard calendar the week starts on Sunday; on the european calendar the week starts 
			on Monday.  
		Note:  This calendar has only been tested On Microsoft IE 5.5 and Netscape 4.75.
		
		Parameters
		Month -  The month the calendar will display.  The default is current month.
		Year -  The year the calendar will display.  The default is current year.
		Field -  This is the form.field name that will be populated when a date is selected.  There is no default.
	*/

	var CalendarEvents=new WddxRecordset();_t2=new Array();_t2[0]=1;_t2[1]=2;_t2[2]=3;_t2[3]=4;_t2[4]=4;_t2[5]=5;_t2[6]=6;_t2[7]=6;_t2[8]=7;_t2[9]=9;_t2[10]=9;_t2[11]=10;_t2[12]=10;_t2[13]=11;_t2[14]=12;_t2[15]=1;_t2[16]=3;_t2[17]=3;_t2[18]=3;_t2[19]=4;_t2[20]=4;_t2[21]=5;_t2[22]=5;_t2[23]=6;_t2[24]=7;_t2[25]=9;_t2[26]=9;_t2[27]=9;_t2[28]=10;_t2[29]=11;_t2[30]=11;_t2[31]=12;CalendarEvents["month"]=_t2;_t2=new Array();_t2[0]=1;_t2[1]=14;_t2[2]=17;_t2[3]=1;_t2[4]=15;_t2[5]=18;_t2[6]=14;_t2[7]=16;_t2[8]=4;_t2[9]=7;_t2[10]=11;_t2[11]=14;_t2[12]=31;_t2[13]=28;_t2[14]=25;_t2[15]=21;_t2[16]=20;_t2[17]=24;_t2[18]=31;_t2[19]=7;_t2[20]=14;_t2[21]=12;_t2[22]=27;_t2[23]=21;_t2[24]=28;_t2[25]=2;_t2[26]=16;_t2[27]=23;_t2[28]=27;_t2[29]=11;_t2[30]=30;_t2[31]=21;CalendarEvents["day"]=_t2;_t2=new Array();_t2[0]=0;_t2[1]=0;_t2[2]=0;_t2[3]=0;_t2[4]=0;_t2[5]=0;_t2[6]=0;_t2[7]=0;_t2[8]=0;_t2[9]=0;_t2[10]=0;_t2[11]=0;_t2[12]=0;_t2[13]=0;_t2[14]=0;_t2[15]=2002;_t2[16]=2002;_t2[17]=2002;_t2[18]=2002;_t2[19]=2002;_t2[20]=2002;_t2[21]=2002;_t2[22]=2002;_t2[23]=2002;_t2[24]=2002;_t2[25]=2002;_t2[26]=2002;_t2[27]=2002;_t2[28]=2002;_t2[29]=2002;_t2[30]=2002;_t2[31]=2002;CalendarEvents["year"]=_t2;_t2=new Array();_t2[0]="New Years\' Day";_t2[1]="Valentine\'s Day";_t2[2]="St. Patrick\'s Day";_t2[3]="April Fools Day";_t2[4]="Federal Income Tax Filling Due";_t2[5]="Armed Forces Day";_t2[6]="Flag Day";_t2[7]="Father\'s day";_t2[8]="US Independence Day";_t2[9]="Rosh Hashanah";_t2[10]="Patriot Day";_t2[11]="Columbus Day";_t2[12]="Holloween";_t2[13]="Thanksgiving Day";_t2[14]="Christmas Day";_t2[15]="Martin Luther King";_t2[16]="Beginning of Spring";_t2[17]="Palm Sunday";_t2[18]="Easter";_t2[19]="Daylight Savings Time Begins";_t2[20]="Earth Day";_t2[21]="Mother\'s Day";_t2[22]="Memorial Day";_t2[23]="Summer Begins";_t2[24]="Parent\'s Day";_t2[25]="Labor Day";_t2[26]="Yom Kippur";_t2[27]="Autumn Begins";_t2[28]="Standard Time Resumes";_t2[29]="Veterans Day";_t2[30]="Chanukah";_t2[31]="Winter Begins";CalendarEvents["description"]=_t2;_t2=new Array();_t2[0]="";_t2[1]="Red";_t2[2]="Green";_t2[3]="";_t2[4]="";_t2[5]="Violet";_t2[6]="";_t2[7]="";_t2[8]="";_t2[9]="";_t2[10]="";_t2[11]="";_t2[12]="Orange";_t2[13]="";_t2[14]="";_t2[15]="";_t2[16]="";_t2[17]="Purple";_t2[18]="Yellow";_t2[19]="";_t2[20]="Green";_t2[21]="";_t2[22]="";_t2[23]="";_t2[24]="";_t2[25]="";_t2[26]="";_t2[27]="";_t2[28]="";_t2[29]="";_t2[30]="";_t2[31]="";CalendarEvents["color"]=_t2;_t0=null;_t1=null;_t2=null; 
	var border = 1;  // The size of the table border
	var cellspacing = 0;  // The size of the table cell spacing
	var cellpadding = 0;  // The size of the table cell padding
	var language = 1; 	// language (0 = spanish, 1 = english, 2 = portuguese)
	var style = 0; // style (0 = Standard, 1 = Europeon)
	var dateField = null;  // this will contain the form field object to which the date value will be return to
	var txtColor = "Navy";

	function setLanguage(value) {
	// Set the language 
	
		language = parseInt(value);
	}

	function setCalendar() {

		var now = new Date();  // Todays date
		var month = 0;
		var year = 0;

		if (arguments[0] == null)
			month = now.getUTCMonth();  // This month
		else
			month = arguments[0];  // Selected month
		
		if (arguments[1] == null)
			year = now.getUTCFullYear();  // This year
		else
			year = arguments[1];  // Selected year

		if (month < 0) {
			year--;
			month = 11;
		}
		
		if (month > 11) {
			year++;
			month = 0; 
		}
		
		if (arguments[2] == null)
			style = 0; //Set the calendar style to Standard
		else
			style = parseInt(arguments[2]); //Set the calendar style to user defined
		
		// number of days in current month
		var days = getNumberOfDaysInMonth(month, year);

		if (month == now.getUTCMonth() & year == now.getUTCFullYear())
			var date = now.getUTCDate();
		var now = null;
		
		// create instance of first day of the month and extract the day on which it occurs
		var firstDayInstance = new Date(year, month, 1);
		var firstDay = firstDayInstance.getUTCDay();
		var firstDayInstance = null;

		// call function ot draw the calendar
		drawCalendar(firstDay + 1, days, date, month, year);
		return;
	}
	
	// build the calendar
	function drawCalendar(firstDay, lastDate, date, month, year) {
		// variables initialization
		var html = ""; // initialize variable
		var dayOfMonth = 1; // first day of month
		var currentCell = 0; // current table cell

		html += '<h1>Calendar</h1>\n';
		html += '<form action="" method="post" name="CalendarPage">\n';
		html += '<table border="' + 0 + '" cellpadding="' + cellpadding + '" cellspacing="' + cellspacing + '" width="100%">\n';
		html += '\t<tr valign="top">\n';
		if (isNetscape4)
			html += '\t\t<td align="center"><input type="button" name="Previous" value="&lt;&lt;&lt;&lt;" style="width: 40px"  onClick="Javascript:setCalendar(' + (month - 1) + ', ' + year +', ' + style + ');"></td>\n';
		else
			html += '\t\t<td align="center"><a href="Javascript:voidFunction();" onclick="Javascript:setCalendar(' + (month - 1) + ', ' + year +', ' + style + ');" class="Submit">&lt;&lt;&lt;&lt;</a></td>\n';
		html += '\t\t<td align="center">\n';
		html += '\t\t\t<select name="Month" size="1" onchange="Javascript:setCalendar(this[this.selectedIndex].value, Year.options[Year.selectedIndex].value,' + style + ');">\n';
		for (var months = 0; months <= 11; months++) {
			if (months == month)
				html += '\t\t\t\t<option value="' + months + '"  class="CalendarHeading" selected>' + getMonthName(months) + '</option>\n';
			else		
				html += '\t\t\t\t<option value="' + months + '"  class="CalendarHeading">' + getMonthName(months) + '</option>\n';
		}
		html += '\t\t\t</select>\n';
		html += '\t\t</td>\n';
		html += '\t\t<td>\n';
		html += '\t\t\t<select name="Year" size="1" onchange="Javascript:setCalendar(Month.selectedIndex, this[this.selectedIndex].value,' + style + ');">\n';
		for (var years = parseInt(year) - 100; years <= parseInt(year) + 100; years++) {
			if (years == year)
				html += '\t\t\t\t<option value="' + years + '"  class="CalendarHeading" selected>' + years + '</option>\n';
			else		
				html += '\t\t\t\t<option value="' + years + '"  class="CalendarHeading">' + years + '</option>\n';
		}
		html += '\t\t\t</select>\n';
		html += '\t\t</td>\n';
		if (isNetscape4)
			html += '\t\t<td align="center"><input type="button" name="Next" value="&gt;&gt;&gt;&gt;" style="width: 40px"  onClick="Javascript:setCalendar(' + (month + 1) + ', ' + year + ', ' + style + ');"></td>\n';
		else
			html += '\t\t<td align="center"><a href="Javascript:voidFunction();" onclick="Javascript:setCalendar(' + (month + 1) + ', ' + year + ', ' + style + ');" class="Submit">&gt;&gt;&gt;&gt;</a></td>\n';
		html += '\t</tr>\n';
		html += '</table><p></p>\n';
		html += '<table border="' + border + '" cellpadding="' + cellpadding + '" cellspacing="' + cellspacing + '" class="calendar" align="center" width="100%">\n';

		//create the days of the week row
		html += '\t<tr align="center" valign="middle">\n';
		for (var dayNum = 0; dayNum < 7; ++dayNum) 
			if (style == 0) 
				if (dayNum == 0 | dayNum == 6)
					html += '\t\t<td class="CalendarWeekendHeading" width="20">' + getDaysOfWeekName((dayNum+style)%7) +  '</td>\n';
				else
					html += '\t\t<td class="ColumnHeading" width="20">' + getDaysOfWeekName((dayNum+style)%7) +  '</td>\n';
			else
				if (dayNum > 4)
					html += '\t\t<td class="CalendarWeekendHeading" width="20">' + getDaysOfWeekName((dayNum+style)%7) +  '</td>\n';
				else
					html += '\t\t<td class="ColumnHeading" width="20">' + getDaysOfWeekName((dayNum+style)%7) +  '</td>\n';
		html += '\t</tr>\n';
		if (style == 1)
			var startOfWeek = (((firstDay - 1) % 7) == 0) ? 7 : ((firstDay - style) % 7);
		else
			var startOfWeek = firstDay - 1;
			
		for (var row = 1; row <= Math.ceil((lastDate + startOfWeek) / 7); ++row) {
			html += '\t<tr align="right" valign="top">\n';
			for (var column = 0; column < 7; ++column) {
		  	    if ((currentCell < startOfWeek-style) || (dayOfMonth > lastDate)) {
						if (style == 0) {
							if (column == 0 | column == 6)
								html += '\t\t<td class="bgweekendbox" width="110" height="80">&nbsp;</td>\n';
							else
								html += '\t\t<td class="bgempty" width="110" height="80">&nbsp;</td>\n';
						}
						else {
							if (column > 4)
								html += '\t\t<td class="bgweekendbox" width="110" height="80">&nbsp;</td>\n';
							else
								html += '\t\t<td class="bgempty" width="110" height="80">&nbsp;</td>\n';
						}
					//html += '\t\t<td class="bgempty" width="110" height="80">&nbsp;</td>\n';
					currentCell++;
	    		 }
				else {
					if (dayOfMonth == date)
	            		html += '\t\t<td class="today" width="110" height="80">' + dayOfMonth;
		    	    else {
						if (style == 0) {
							if (column == 0 | column == 6)
								html += '\t\t<td class="bgweekendbox" width="110" height="80">' + dayOfMonth;
							else
								html += '\t\t<td class="bgbox" width="110" height="80">' + dayOfMonth;
						}
						else {
							if (column > 4)
								html += '\t\t<td class="bgweekendbox" width="110" height="80">' + dayOfMonth;
							else
								html += '\t\t<td class="bgbox" width="110" height="80">' + dayOfMonth;
						}
				}						
				for (var events =0; events <= CalendarEvents.day.length-1; events++) {
					if ((CalendarEvents.year[events] == 0) | (CalendarEvents.year[events] == year) && (CalendarEvents.month[events]-1 == month) && (CalendarEvents.day[events] == dayOfMonth)) {
						var holidayColor = (CalendarEvents.color[events]  > "") ? CalendarEvents.color[events] : txtColor ;
						html +=  '<span style="font-size: 11px;color:' + holidayColor + '"><br>&nbsp;' + CalendarEvents.description[events] + '</span>';				
					}
				}
				html += '</td>\n';
	    	  	dayOfMonth++;
	        }
   		 }
			html += '\t</tr>\n';
		} 
		
		// close table and body
		html += '</table>\n';
		html += '<table border="0" cellpadding="' + cellpadding + '" cellspacing="' + cellspacing + '" align="center">\n';
		html += '\t<tr>\n';
		html += '\t\t<td class="CalendarHeading">\n';
		if (style == 0)
			html += '\t\t\t<input type="radio" name="style" value="0" checked onclick="Javascript:setCalendar(Month.options[Month.selectedIndex].value, Year.options[Year.selectedIndex].value, this.value)"> ' + getStyleText(0) + '&nbsp;\n';
		else
			html += '\t\t\t<input type="radio" name="style" value="0" onclick="Javascript:setCalendar(Month.options[Month.selectedIndex].value, Year.options[Year.selectedIndex].value, this.value)"> ' + getStyleText(0) + '&nbsp;\n';
		if (style == 1)
			html += '\t\t\t<input type="radio" name="style" value="1" checked onclick="Javascript:setCalendar(Month.options[Month.selectedIndex].value, Year.options[Year.selectedIndex].value, this.value)"> ' + getStyleText(1) + '\n';
		else
			html += '\t\t\t<input type="radio" name="style" value="1" onclick="Javascript:setCalendar(Month.options[Month.selectedIndex].value, Year.options[Year.selectedIndex].value, this.value)"> ' + getStyleText(1) + '\n';
		html += '\t\t</td>\n';
		html += '\t</tr>\n';
		html += '</table>\n'; 
		html += '</form>\n';

		if (isNetscape4) {
			document.layers.nCalendar.document.write(html);
			document.layers.nCalendar.document.close();
		}
		else
			if (isIE) 
				document.all.Calendar.innerHTML = html;
			else if (isNetscape6)
				document.getElementById("Calendar").innerHTML=html;

		return;
	}

	function getNumberOfDaysInMonth(month, year) {
		// create an array to hold the number of days in each month
		var daysInMonth = new Array(12);

		daysInMonth[0] = 31;  // January
		daysInMonth[1] = (isLeapYear(year)) ? 29 : 28;  // February
		daysInMonth[2] = 31;  //  March
		daysInMonth[3] = 30;  // April
		daysInMonth[4] = 31;  // May
		daysInMonth[5] = 30;  // June
		daysInMonth[6] = 31;  // July
		daysInMonth[7] = 31;  // August
		daysInMonth[8] = 30;  // September
		daysInMonth[9] = 31;  // October
		daysInMonth[10] = 30;  // November
		daysInMonth[11] = 31;  // December

		// return the number of days in the specified month
		return daysInMonth[month];
	}
	
	function isLeapYear(year) {
		// Check if leap year
		return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	}
	
	function getMonthName(month) {
		// create an array to hold the names of the months
		var monthName = new Array(12);
		
		switch (language) {
			case 0:
				monthName[0] = "enero";
				monthName[1] = "febrero";
				monthName[2] = "marzo";
				monthName[3] = "abril";
				monthName[4] = "mayo";
				monthName[5] = "junio";
				monthName[6] = "julio";
				monthName[7] = "agosto";
				monthName[8] = "septiembre";
				monthName[9] = "octubre";
				monthName[10] = "noviembre";
				monthName[11] = "diciembre";
			break;
			case 1:
				monthName[0] = "January";
				monthName[1] = "February";
				monthName[2] = "March";
				monthName[3] = "April";
				monthName[4] = "May";
				monthName[5] = "June";
				monthName[6] = "July";
				monthName[7] = "August";
				monthName[8] = "September";
				monthName[9] = "October";
				monthName[10] = "November";
				monthName[11] = "December";
			break;
			case 2:
				monthName[0] = "janeiro";
				monthName[1] = "fevereiro";
				monthName[2] = "mar&ccedil;o";
				monthName[3] = "abril";
				monthName[4] = "maio";
				monthName[5] = "junho";
				monthName[6] = "julho";
				monthName[7] = "agosto";
				monthName[8] = "setembro";
				monthName[9] = "outubro";
				monthName[10] = "novembro";
				monthName[11] = "dezembro";
			break;
		}
		
		// return the name of the month in the specified language
		return monthName[month];
	}
	
	function getDaysOfWeekName(day) {
		// create an array to hold the days of the week in the specified language
		var weekDay = new Array(7);

		switch (language) {
			case 0:
				weekDay[0] = 	"domingo";
				weekDay[1] = 	"lunes";
				weekDay[2] = 	"martes";
				weekDay[3] = 	"mi&eacute;rcoles";
				weekDay[4] = 	"jueves";
				weekDay[5] = 	"viernes";
				weekDay[6] = 	"s&aacute;bado";
			break;
			case 1:
				weekDay[0] = 	"Sunday";
				weekDay[1] = 	"Monday";
				weekDay[2] = 	"Tueday";
				weekDay[3] = 	"Wednesday";
				weekDay[4] = 	"Thursday";
				weekDay[5] = 	"Friday";
				weekDay[6] = 	"Saturday";
			break;
			case 2:
				weekDay[0] = 	"domingo";
				weekDay[1] = 	"segunda-feira";
				weekDay[2] = 	"ter&ccedil;a-feira";
				weekDay[3] = 	"quarta-feira";
				weekDay[4] = 	"quinta-feira";
				weekDay[5] = 	"sexta-feira";
				weekDay[6] = 	"saacute;bado";
			break;
		}	
		
		// return the day of the week in the specified language
		return weekDay[day];
	}
	
	function getStyleText(style) {
		// create an array to hold the style text specified language
		var styleText = new Array(2);

		switch (language) {
			case 0:
				styleText[0] = 	"Normal";
				styleText[1] = 	"Euro";
			break;
			case 1:
				styleText[0] = 	"Standard";
				styleText[1] = 	"Euro";
			break;
			case 2:
				styleText[0] = 	"Normal";
				styleText[1] = 	"Euro";
			break;
		}	
		
		// return the style text in the specified language
		return styleText[style];
	}

