

/* CUSTOMIZATIONS HERE */

// default table style
var rci_table_style = "";
//var rci_table_style = "background-color: #FFFFFF;";

// sets the "grid" color; leave blank if none desired
var rci_table_grid_color = "#d2edff";

// URL link to events; passes the date in form "?d=mm/dd/yy"
var rci_event_link = "/events/index.php";

// style for the header TR row
var rci_header_style = "background-color: #d2edff; font-family: Arial; font-size: 13px; text-decoration: none;";

// style for the forward and backward objects
var rci_prev_next_style = "color: #08307b; text-decoration: none; ";

// object to dump into the placeholder; can use <img src="xx.jpg"> or "<<"
var rci_prev_month_object = "&nbsp;&lt;&lt;"

// object to dump into the placeholder; can use <img src="xx.jpg"> or ">>"
var rci_next_month_object = "&gt;&gt;&nbsp;"

// sets up the month alignement; "left", "right", or "center"
var rci_month_alignment = "center"

// sets up the weekday header style
var rci_weekday_header_style = "background-color: #08307b; color: #FFFFFF; text-align: center; font-family: Arial; font-size: 11px; ";

// sets up the current day if it has an event
var rci_current_day_style = "background-color: #08307b; color: FFFFFF; font-family: Verdana; font-size: 11px; text-align: center;"

// sets up the current day text style that will have events
var rci_current_day_text_style_events = "color: #FFFFFF; font-family: Verdana; font-size: 10px; font-weight: bold; text-decoration: underline; text-align: center;";

// sets up the current day text style that has no events
var rci_current_day_text_style_no_events = "color: #FFFFFF; font-family: Verdana; font-size: 10px; text-decoration: none; text-align: center;";

// sets up regular day style
var rci_day_style = "background-color: #d2edff; color:#000000; text-align: center; vertical-align:middle;";
//var rci_day_style = " background-color: #F1E5D7; color:#000000;";

// sets up regular day style with events
var rci_day_text_events = " font-family: Verdana; font-size: 10px; font-weight: normal; text-decoration: underline; color: #8397bd;";

// sets up regular day style with no events
var rci_day_text_no_events = "font-family: Verdana; font-size: 10px; color: #000000;";

// set up the row height; set to "" if none specific; use 'height="15px"' as an example
var rci_row_height = 'height="24px"';

/* ===================================== */
/* ===   DO NOT EDIT BELOW THIS LINE === */
/* ===================================== */

var ns6=document.getElementById&&!document.all
var ie4=document.all
var Selected_Month;
var Selected_Year;
var Current_Date = new Date();
var Current_Month = Current_Date.getMonth();
var Days_in_Month = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var Month_Label = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
var Current_Year = Current_Date.getYear();
if (Current_Year < 1000)
Current_Year+=1900
var Today = Current_Date.getDate();

function Header(Year, Month) {
   if (Month == 1) {
   Days_in_Month[1] = ((Year % 400 == 0) || ((Year % 4 == 0) && (Year % 100 !=0))) ? 29 : 28;
   }
   var Header_String = Month_Label[Month] + ' ' + Year;
   return Header_String;
}




function Make_Calendar(Year, Month) {

	var vMonth = Month+1
	var vYear = Year
	var vBold = false
	
	var First_Date = new Date(Year, Month, 1);
	var Heading = Header(Year, Month);
	var First_Day = First_Date.getDay() + 1;
	
	// the next lines figuire out how many rows are needed
	if (((Days_in_Month[Month] == 31) && (First_Day >= 6)) ||
		((Days_in_Month[Month] == 30) && (First_Day == 7))) {
		var Rows = 6;
	}
	else if ((Days_in_Month[Month] == 28) && (First_Day == 1)) {
		var Rows = 4;
	}
	else {
		var Rows = 5;
	}

	//Build the surrounding table and the rows for back and forward as well as the current month, and the weekday legend
	
	//Sets up the action for us
	var HTML_String = '<table style="' + rci_table_style + '" border="0" width="230" cellspacing="0" cellpadding="0"><tr><td valign="top"><table bgcolor="' + rci_table_grid_color + '" cellpadding="1" cellspacing="1" border="0" width="100%">';
	
	//Builds out the top row of the data; styles imported from above as variables
	HTML_String += '<tr style="' + rci_header_style + '"><th align="left"><a style="' + rci_prev_next_style + '" href="javascript:Skip(\'-\');">' + rci_prev_month_object + '</a></th><th colspan="5" align="' + rci_month_alignment + '">' + Heading + '</th><th align="right"><a style="' + rci_prev_next_style + '" href="javascript:Skip(\'+\');">' + rci_next_month_object + '</a></th></tr>'

	//Builds out the weekday headers info
	HTML_String += '<tr style="' + rci_weekday_header_style + '"><td style="' + rci_weekday_header_style + '"><strong>S</strong></td><td style="' + rci_weekday_header_style + '"><strong>M</strong></td><td style="' + rci_weekday_header_style + '"><strong>Tu</strong></td><td style="' + rci_weekday_header_style + '"><strong>W</strong></td><td style="' + rci_weekday_header_style + '"><strong>Th</strong></td><td style="' + rci_weekday_header_style + '"><strong>F</strong></td><td style="' + rci_weekday_header_style + '"><strong>S</strong></td></tr>'

	//Initialize counters for day and loop
	var Day_Counter = 1;
	var Loop_Counter = 1;

	
	
	for (var j = 1; j <= Rows; j++) {
		//Begin the loop
		
		//Write the initial TR tag
		HTML_String += '<tr ALIGN="center" VALIGN="top" '+ rci_row_height + '>';


		for (var i = 1; i < 8; i++) {
			//Begin the loop of weekdays
			
			vTDate = vMonth+"/"+Day_Counter+"/"+vYear;
			vLinkDate = rci_event_link + '?y=' + vYear +'&m='+vMonth+'&d='+Day_Counter;
			/*
			if (vDates.indexOf(vTDate,0) > 0 ) {
				vBold = true;
			} else {
				vBold = false;
				
			}
			*/
			
			vBold = true;
			
			//Test to see if it's a first or last day
			if ((Loop_Counter >= First_Day) && (Day_Counter <= Days_in_Month[Month])) {

				//Means this isn't a first or last day

				//Test to see if the day we are writing is today, if so, apply highlight style
				if ((Day_Counter == Today) && (Year == Current_Year) && (Month == Current_Month)) {
					
					if (vBold==true) {
						// Means it is today and today has events;
						HTML_String += '<td style="' + rci_current_day_style + '"><a style="' + rci_current_day_text_style_events + '" title="See events for this day" href="' + vLinkDate + '">' + Day_Counter + '</strong></font></a></td>'
					} else {
						// Means it is today, and has no events
						HTML_String += '<td style="' + rci_current_day_style + '"><span style="' + rci_current_day_text_style_no_events + '">' + Day_Counter + '</span></td>'			
					}
				} else {
					// It's not today, so apply a regular day style
					if (vBold==true) {
						// The day has events, apply a link and style					
						HTML_String += '<td style="' + rci_day_style + '"><a style="' + rci_day_text_events + '" href="' + vLinkDate + '"><strong>' + Day_Counter + '</strong></font></td>';
					} else {
						// The day has no events, apply a style
						HTML_String += '<td style="' + rci_day_style + '"><span style="' + rci_day_text_no_events + '">' + Day_Counter + '</span></td>';
					}
				}
			//Increase our daily counter
			Day_Counter++;    
			}
			//This means it's not a valid day
			else {
				HTML_String += '<td style="' + rci_day_style + '"></td>';
			}
			//We're at the end of the loop, so increase our loop counter
			Loop_Counter++;
		}
		HTML_String += '</tr>';
	}
	//Clean up our HTML string and write it big dog!!!
	HTML_String += '</table></td></tr></table>';
	cross_el=ns6? document.getElementById("rci_calendar") : document.all.rci_calendar
	cross_el.innerHTML = HTML_String;
}

function Check_Nums() {
   if ((event.keyCode < 48) || (event.keyCode > 57)) {
      return false;
   }
}



function On_Year() {
   var Year = document.when.year.value;
   if (Year.length == 4) {
      Selected_Month = document.when.month.selectedIndex;
      Selected_Year = Year;
      Make_Calendar(Selected_Year, Selected_Month);
   }
}

function On_Month() {
   var Year = document.when.year.value;
   if (Year.length == 4) {
      Selected_Month = document.when.month.selectedIndex;
      Selected_Year = Year;
      Make_Calendar(Selected_Year, Selected_Month);
   }
   else {
      alert('Please enter a valid year.');
      document.when.year.focus();
   }
}


function Defaults() {
   if (!ie4&&!ns6)
   return
   var Mid_Screen = Math.round(document.body.clientWidth / 2);
   //document.when.month.selectedIndex = Current_Month;
   //document.when.year.value = Current_Year;
   Selected_Month = Current_Month;
   Selected_Year = Current_Year;
   //alert('M: '+Selected_Month+' Y:'+Selected_Year);
   Make_Calendar(Current_Year, Current_Month);
}

function BuildCalendarMonth( xYear,xMonth,xDay ) {
   if (!ie4&&!ns6)
   return
   var Mid_Screen = Math.round(document.body.clientWidth / 2);
   //document.when.month.selectedIndex = Current_Month;
   //document.when.year.value = Current_Year;
   
   var xDate = new Date(xMonth+"/"+ xDay +"/"+xYear);
   
   Selected_Month = xDate.getMonth();
   Selected_Year = xDate.getFullYear();
   Current_Month = Selected_Month;
   Current_Year = Selected_Year;
   Current_Date = xDate;
   Today = xDate.getDate();
   //alert('M: '+Selected_Month+' Y:'+Selected_Year);
   Make_Calendar(Selected_Year, Selected_Month);
}


function Skip(Direction) {
	if (Direction == '+') {
		if (Selected_Month == 11) {
			Selected_Month = 0;
			Selected_Year++;
		}
		else {
			Selected_Month++;
		}
	}
	else {
		if (Selected_Month == 0) {
			Selected_Month = 11;
			Selected_Year--;
		}
		else {
			Selected_Month--;
		}
	}
	Make_Calendar(Selected_Year, Selected_Month);
	//document.when.month.selectedIndex = Selected_Month;
	//document.when.year.value = Selected_Year;
}

