var sEventHTML = ""
//document.write("<Div id=\"details\"><table cellpadding=\"4\" cellspacing=\"0\" style=\"width:100%;\"><tr class=\"cssEventDetailsHeader\"><td><b>Event Details</b></td><td align=\"right\"><span style=\"cursor:pointer; font-size:11px\" onclick=\"javascript: opacity('details', 100, 0, 500);\">close</span></td></tr><tr><td style=\"width:100%; padding:5px;\" colspan=2 id=\"eventDetails\"></td></tr></table></div>")

function checkForCurrentDay(sMonth, sYear){
	var curDate = new Date()
	var sClass = ""
	var oCell = document.getElementById(curDate.getDate());
	if(oCell.className=="cssEventScheduled"){
		sClass="cssEventCurrentDay"
		oCell.style.padding="0px";
	}else{
		sClass="cssCurrentDay"	
		oCell.style.padding="0px";
	}
	oCell.title="Today"
	if(sYear==curDate.getYear() && sMonth==curDate.getMonth()){

		//determine whether it is an event as well as today
		if(sClass=="cssEventCurrentDay"){
			oCell.innerHTML = "<div class=\"" + sClass + "\" onClick=\"findPos(" + curDate.getDate() + "," + curDate.getMonth() + "," + curDate.getYear() + "," + curDate.getDate() + ")\">" + oCell.innerText + "</div>"
		}else{
			oCell.innerHTML = "<div class=\"" + sClass + "\">" + oCell.innerText + "</div>"
		}

	}

}
function parseEventData(sMonth, sYear){
	var ar = document.getElementById("eventdata").value.split("~~")
	
	//check if there is an event falling on that day
	for(i=0; i < ar.length-1; i++){
		var ar2 = ar[i].split("|")
		var eDate = ar2[2].split("/")
		//eDate[0] = month
		//eDate[1] = day
		//eDate[2] = year
		var newClass="cssEventScheduled"
		if(sMonth==(eDate[0]-1) && sYear==eDate[2]){
			var oCell = document.getElementById(eDate[1])
			if(document.getElementById(eDate[1]).className != newClass){
				document.getElementById(eDate[1]).className=newClass;
				oCell.style.padding="0px";
//				oCell.onClick="findPos(eDate[1],sMonth,sYear,eDate[1]);"
				oCell.innerHTML="<div onClick=\"findPos(" + eDate[1] + "," + sMonth + "," + sYear + "," + eDate[1] + ")\" class=\"cssEventScheduled\">" + oCell.innerHTML + "</div>"
			}
			var sDetails=ar2[1]
			
		}
	}
checkForCurrentDay(sMonth, sYear)
}
function drawCal(sPrevMonth,sMonth, sYear){
//	alert("sPrevMonth: " + sPrevMonth + ", sMonth: " + sMonth);
//	alert("sMonth= " + sMonth)
<!--
// Set varible to the current date
var right_now=new Date();

var curDate = new Date();

// set variable to current month number (0-11)
if(sMonth == null){
	var month_num = right_now.getMonth()
}else{
	if(sMonth == -1){
		var month_num=11
	}else if(sMonth > 11){
		var month_num=0
	}else{
		var month_num=sMonth	
	}

	if(sPrevMonth == -1){
		var sPrevMonth=11
	}else if(sPrevMonth > 11){
		var sPrevMonth=0
	}

}
//document.write(month_num);

// set varible to the current day value (1-31)
var thedate=right_now.getDate()

// create an array for the month name
var month_name = new Array (
	"January ",
	"February ",
	"March ",
	"April ",
	"May ",
	"June ",
	"July ",
	"August ",
	"September ",
	"October ",
	"November ",
	"December ");

// Create a varible right_year with the current year
	
	if (sYear == null){
		var right_year=right_now.getYear();
	}else{
		var right_year=sYear	
	}
		if (right_year < 2000) 
		right_year = right_year + 1900; 

	//enable this code to cycle through the years.  It has been disabled to allow for downloading of currently selected year only.
	if(sPrevMonth != null){	
		if(parseInt(sPrevMonth) < parseInt(sMonth) && parseInt(sMonth) > 11){
			right_year = parseInt(right_year) + 1;	
		}
		if(parseInt(sPrevMonth) > parseInt(sMonth) && parseInt(sMonth) < 0){
			parseInt(right_year -= 1);
		}
	}

// create a varible to specify what the
// last day for the current month is
var theday = 0;
if (
	month_num == 0 || 
	month_num == 2 || 
	month_num == 4 || 
	month_num == 6 || 
	month_num == 7 || 
	month_num == 9 || 
	month_num == 11)
{ 
	endofmonth=31;
}

if (
	month_num == 3 || 
	month_num == 5 || 
	month_num == 8 || 
	month_num == 10)
{ 
	endofmonth=30;
}

if (month_num == 1)
{ 
// This will check for a leap year
// If the year is evenly divisible by four
// or in the case of a new century evenly divisible
// by 400 then the end of the February month should be the 29th

right_year_divided=right_year/4;
right_year_divided_string= new String(right_year_divided);
var is_decimal = right_year_divided_string.indexOf('.');
if (is_decimal != -1)
{ endofmonth=28; }
else
{ endofmonth=29; }

right_year_string= new String(right_year);
var the_century=new String(right_year_string.charAt(2)) 
the_century= the_century + new String(right_year_string.charAt(3));
if (the_century == "00")
{ 
right_year_divided=right_year/400;
right_year_divided_string= new String(right_year_divided);
var is_decimal = right_year_divided_string.indexOf('.');
if (is_decimal != -1)
{endofmonth=28;}
else
{endofmonth=29;}
}
}

//document.getElementById("container").innerHTML="";
//var sHTML = ""
// Start building the table
//var sHTML="<div align=center>Previous Month: " + sPrevMonth + ", Current Month: " + sMonth + "</div>";

var sHTML="<table border=0 cellspacing=1 cellpadding=0 id=cssEventCalTable align=center>"
sHTML+="<tr><td class=\"cssChangeMonth\" onclick=\"drawCal(" + month_num + "," + (parseInt(month_num)-1) + ",'" + right_year + "')\"><<</td><td colspan=5 class=\"cssMonthLabel\">" + month_name[month_num] + " " + right_year + "</td><td class=\"cssChangeMonth\" onclick=\"javascript:drawCal('" + month_num + "','" + (	parseInt(month_num)+1) + "','" + right_year + "')\">>></td></tr>"

// Write the table header row
sHTML+="<tr class=\"cssDayRow\"><th>S</th><th>M</th><th>T</th><th>W</th>"
sHTML+="<th>R</th><th>F</th><th>S</th></tr><tr>"

// Figure out which day of the week the 1st of the 
// current month belongs to
first_day = new Date(right_year,month_num,1)


// Write the first row in the calendar with dates
// Check which date of the month is the first to
// fill it into the appropriate day of the week
for (counter = 0; counter < 7; counter++)
{ 

	// Check the counter aganst the first day of the month value (0 - 6)

	if (counter >= first_day.getDay() ) 
	{ 
		// Start counter for the calendar days
		theday=theday+1;
		
			// Check if the current day is in the first week if so, place bold text
			if (theday == thedate && parseInt(sMonth)==curDate.getMonth()) {
				sHTML+="<td class=\"cssNonEmptyCell\" id=\"" + theday + "\"><b>" + theday + "</b></td>"
			// If it's not the current date output without bold text
			}else{
				sHTML+="<td class=\"cssNonEmptyCell\" id=\"" + theday + "\">" + theday + "</td>"
			}		
	// if there is no day yet output an empty cell
	}else{
		sHTML+="<td class=\"cssEmptyCell\"></td>" 
	}
	sHTML += "</td>"
}

// End row for the first week of the month
sHTML+="</tr>" 

// Loop for the rest fo the weeks in the month 
for (weeks = 0; weeks < 5; weeks++)
{ 
sHTML+="<tr>" 
// loop for the days with the remaining weeks
for (week = 0; week < 7; week++)
{

// counter for the day of the month
theday=theday+1

// if the couter = the current date display in bold 
if (theday == thedate) 
{sHTML+="<td class=\"cssNonEmptyCell\" id=\"" + theday + "\">" + theday + "</td>"}
else 
{ 

// if the counter is higher then than the number of days
// in the month then display a blank cell
if (theday > endofmonth) 
{sHTML+="<td class=\"cssEmptyCell\" id=\"" + theday + "\"></td>"}
else 

// If it's not the cureent day display the date wioth bold type
{sHTML+="<td class=\"cssNonEmptyCell\" id=\"" + theday + "\">" + theday + "</td>" }
}
}
sHTML+="</tr>";
}
sHTML+="</table>";
//alert(sHTML)

//document.write(sHTML)
document.getElementById("eventCalendar").innerHTML=sHTML;
parseEventData(month_num, right_year);

//alert(document.getElementById("container").innerHTML)
//-->
}


//find the position of the Calendar, and load the details window.  This function is called when an event is clicked on.
//parse and load the event data into the details window, as well.
function findPos(sDay, sMonth, sYear, cell) {
	document.getElementById("details").style.visibility='visible';
	var obj = document.getElementById("cssEventCalTable")
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
//	return [curleft,curtop];

	//parse the event data
	sEventHTML="<table cellpadding=\"4\" cellspacing=\"0\" border=0>"
	var ar = document.getElementById("eventdata").value.split("~~")
	//check if there is an event falling on that day
	for(i=0; i < ar.length-1; i++){
		var ar2 = ar[i].split("|")
		var eDate = ar2[2].split("/")
		//eDate[0] = month
		//eDate[1] = day
		//eDate[2] = year
		var newClass="cssEventScheduled"
		if(sMonth==(eDate[0]-1) && sYear==eDate[2] && sDay==eDate[1]){
			var oCell = document.getElementById(eDate[1])
//			oCell.title=ar2[1] + "\n" + ar2[2] + "\n" + ar2[3] + " - " + ar2[4] + "\n" + ar2[5] + "\n"
			document.getElementById(eDate[1]).className=newClass;
			var sDetails=ar2[1]
			sEventHTML += "<tr><td style=\"width:100%;\"><b><a href=\"viewEvents.asp?e=" + ar2[0] + "\">" + ar2[1] + "</a></b><br />" + eDate[0] + "/" + eDate[1] + "/" + eDate[2] + "<br />" + ar2[6] + "</td><td style=\"vertical-align:top;\" nowrap>" + ar2[4] + " - " + ar2[5] + "</td></tr><tr><td colspan=\"2\"><div class=\"cssDetailsHR\"><img src=\"images/spacer.gif\" alt=\"\" height=\"1\" width=\"1\" /><br /></div></td></tr>"
			//oCell.innerHTML="<div onClick=\"findPos('" + eDate[1] + "')\" class=\"cssEventScheduled\">" + oCell.innerHTML + "</div>"
		}
	}
	sEventHTML+="</table>"
	document.getElementById("eventDetails").innerHTML = sEventHTML	//inner cell of the details window
	document.getElementById("details").style.top=curtop+"px"
	document.getElementById("details").style.left=curleft+175+"px"
	opacity('details', 0, 100, 500); 
	sEventHTML=""
}

// ** LOAD THE DIV using transparency **

function opacity(id, opacStart, opacEnd, millisec) { 
	document.getElementById(id).style.opacity=0;
	document.getElementById(id).style.visibility='visible'
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
	
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 
