// JScript source code


var scheduleLine;
var scheduleOnLine;

// fill the month table with column headings
function day_title(day_name){
	/* document.write("<TD ALIGN=center WIDTH=35>"+day_name+"</TD>") */
	return "<TD ALIGN=center WIDTH=40>"+day_name+"</TD>";
}

// --
// -- Returns
// --		IsLeapYear:		true
// --		Not IsLeapYear: false
// --
function isLeapYear(datea)
{
	datea = parseInt(datea);

	if(datea%4 == 0)
	{
		if(datea%100 != 0)
		{
		
			return true;
		}
		else
		{
			if(datea%400 == 0)
				return true;
			else
				return false;
		}
	}
	return false;
}



function monthName(month)
{
	var str = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
	return str[month];
}

function daysInMonth(month, year)
{
	var daysNoLeapYear = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	var daysLeapYear = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	var rValue;
	
	if(isLeapYear(year))
	{
		rValue = daysLeapYear[month];
	}
	else
	{
		rValue = daysNoLeapYear[month];
	}
	
	return rValue;
}


// --
// -- Add (subtract) one month from a date object
// --
// -- offset: 1, adds one month -1, subtacts one month
// --
function addMonth(date, offset)
{
	var m;		// Month Variable
	var y;		// Year Variable
	
	
	m = date.getMonth();
	y = date.getFullYear();
	
	m += offset;
	if(m < 0)
	{
		y--;
		m = 11;
	}
	
	if(m > 11)
	{
		y++;
		m = 0;
	}
	date.setFullYear(y);
	date.setMonth(m);
	
	return date;
}

function dateCompare(d1, d2)
{
	var rValue;
	var d1C = d1.getTime();
	var d2C = d2.getTime();
	rValue = false;
	
	if(d1C == d2C)
		rValue = true;
	
	return rValue;
}
function returnClass(eventListId, date)
{
	var rValue;
	var i;	
	var srcDate;
	var lTable = document.getElementById(eventListId);
	var srcRows = lTable.rows.length;
	
	rValue = "";
	for(i=1; i<srcRows; i++)
	{
		lCell = lTable.rows[i].cells[0];		// Get the cell object
		srcDate = new Date(Date.parse(lCell.innerHTML));
		
		//if(srcDate == date)
		if(dateCompare(srcDate,date))
		{
			rValue = lTable.rows[i].cells[3].innerHTML;
			break;
		
		}		
	}
	
	
	return rValue;
}

function isEvent(eventListId, date)
{
	var rValue;
	var i;
	var srcDate;
	var lCell;
	var lTable = document.getElementById(eventListId);
	var srcRows = lTable.rows.length;
	rValue = false;
	for(i=1; i<srcRows; i++)
	{
		lCell = lTable.rows[i].cells[0];		// Get the cell object
		srcDate = new Date(Date.parse(lCell.innerHTML));
		
		//if(srcDate == date)
		if(dateCompare(srcDate,date))
		{
			rValue = true;
			break;
		}	
	}
		
	return rValue;
	
}

function get_schedule_num(eventListId, date)
{
    var rValue;
    var i;
    var schCount;
    var srcDate;
    var lCell;
    
    var lTable = document.getElementById(eventListId);
    var srcRows = lTable.rows.length;
    
    schCount = 0;
    scheduleOnLine = 0;
    rValue = "";
    
    for(i=scheduleLine; i<srcRows; i++)
    {
        lCell = lTable.rows[i].cells[0];
        srcDate = new Date(Date.parse(lCell.innerHTML));
        
        if(dateCompare(srcDate, date))
        {
            rValue = lTable.rows[i].cells[3].innerHTML;
            scheduleLine = i+1;
            scheduleOnLine = i;
            break;
        }
    }
    
    return rValue;
}

function get_cur_scheduleLine()
{
    var rValue;
    rValue = "";
    
    if(scheduleOnLine > 0)
    {
        rValue = "onmouseover=\"showDay(" + scheduleOnLine + ")\" onmouseout=\"hideDay()\"";
    }
    return rValue;
}

/*
 * Function: fill_day
 * Input: 
 */ 

function fill_day(day, monthNum, year)
{
    var strTemp;
    var searchDate = new Date(Date.parse(monthNum + "/" + day + "/" + year));
    scheduleLine = 1;     // Start at the top of the table
    strTemp = "";
    strTemp += "<TD WIDTH=\"80\" HEIGHT=\"80\" ALIGN=\"left\" VALIGN=\"top\"><TABLE WIDTH=\"100%\" CELLPADDING=\"0\" CELLSPACING=\"1\" BORDER=\"0\">";
    strTemp += "<TR><TD WIDTH=\"20px\" ALIGN=\"LEFT\" VALIGN=\"top\">" + day + "</TD><TD class=\"" + get_schedule_num("fixedSchedule", searchDate) + "\" " +get_cur_scheduleLine()+ " WIDTH=\"60px\">&nbsp;</TD></TR>";
    strTemp += "<TR><TD WIDTH=\"20px\" ALIGN=\"LEFT\" VALIGN=\"top\">&nbsp;</TD><TD class=\"" + get_schedule_num("fixedSchedule", searchDate) + "\" " +get_cur_scheduleLine()+ "WIDTH=\"60px\">&nbsp;</TD></TR>";
    strTemp += "<TR><TD WIDTH=\"20px\" ALIGN=\"LEFT\" VALIGN=\"top\">&nbsp;</TD><TD class=\"" + get_schedule_num("fixedSchedule", searchDate) + "\" " +get_cur_scheduleLine()+ " WIDTH=\"60px\">&nbsp;</TD></TR>";
    strTemp += "<TR><TD WIDTH=\"20px\" ALIGN=\"LEFT\" VALIGN=\"top\">&nbsp;</TD><TD class=\"" + get_schedule_num("fixedSchedule", searchDate) + "\" " +get_cur_scheduleLine()+ " WIDTH=\"60px\">&nbsp;</TD></TR>";
    strTemp += "</TABLE></TD>";
    
    return strTemp;
}
function fill_table(month, month_length, monthNum, year, eventListId)
{
    var rStr;
    var rows;
    var day;
    
    day = 1;            // Start the first day of the month
    rStr = "";
    
    // Create the layout table rows: 1, cols: 1
    //rStr += "<TABLE BORDER = \"2\" CELLSPACING = \"1\" CELLPADDING=\"1\" id=\"monthLayout\" WIDTH=\"560\"><TR><TD>";
    
    // Create the data table
    rStr += "<TABLE BORDER=\"2\" CELLSPACING=\"1\" id=\"monthLayout\" WIDTH=\"560\">"
    rStr += "<TR><TD WIDTH=\"80\">Sun</TD><TD>Mon</TD><TD>Tue</TD><TD>Wed</TD><TD>Thu</TD><TD>Fri</TD><TD>Sat</TD></TR>";
    
    // Add the first week starting under the appropriate day
    rows = 0;
    

	rows = 0;
	rStr += "</TR><TR>";
	
	for (var i=1;i<start_day;i++){
	
		rStr += "<TD WIDTH=\"80\" HEIGHT=\"80\">&nbsp;</TD>";
	}
	// fill the first week of days
	for (var i=start_day;i<8;i++){
		//searchDate = new Date(Date.parse(monthNum + "/" + day + "/" + year));
		
        // rStr += "<TD ALIGN=\"left\" VALIGN=\"right\" WIDTH=\"80\" HEIGHT=\"80\">"+day+"</TD>";		
        rStr += fill_day(day, monthNum, year);
		day++;
	}

	rStr += "<TR>";
	rows++;
	// fill the remaining weeks
	while (day <= month_length) {
		for (var i=1;i<=7 && day<=month_length;i++){
			//searchDate = new Date(Date.parse(monthNum + "/" + day + "/" + year));
            rStr += fill_day(day, monthNum, year);
		    day++;
		}

		// the first day of the next month
		start_day=i
		
		if(start_day-1 < 7)
		{
			for(i=start_day-1; i<7; i++)
			{
				rStr += "<TD WIDTH=\"80\" HEIGHT=\"80\">&nbsp;</TD>";
			}
		}

		rStr += "</TR><TR>";
		rows++;
	}
	if(rows < 6)
	{
		rStr += "<TD WIDTH=\"80\" HEIGHT=\"80\">&nbsp;</TD><TD WIDTH=\"80\" HEIGHT=\"80\">&nbsp;</TD><TD WIDTH=\"80\" HEIGHT=\"80\">&nbsp;</TD><TD WIDTH=\"80\" HEIGHT=\"80\">&nbsp;</TD><TD WIDTH=\"80\" HEIGHT=\"80\">&nbsp;</TD><TD WIDTH=\"80\" HEIGHT=\"80\">&nbsp;</TD><TD WIDTH=\"80\" HEIGHT=\"80\">&nbsp;</TD></TR><TR>";
	}


    // End of data table
    rStr += "</TABLE>"; 
    // End of layout table.
    //rStr += "</TD></TR></TABLE>";
  
    return rStr; 
    
}







function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}
